jeudi 29 octobre 2020

Close Browser's find (CTRL + F)

I am creating a script to register where users are making CTRF + F in my website. For this I made a code that look every time the user is calling the browser's find and I push into an array the name of the page where he did it. Some of my page are in reality tabs that mean that the browser's find doesn't close it self when I change tab. So I would like to have a script to close the browser's when I change tab or page beacuse if not the browser's find could stay open even if the user change tab and do an other research. For now I have this:

var ctrlf = []; 
var url = '';
window.addEventListener("keydown", (event) => {
url = url_parse();
  if ((event.ctrlKey && (event.key == "f")) || (event.key == "F3")) {
    ctrlf.push(url_parse());
//url_parse is a function to parse the url of the page into a string (see this as the id of a page / tab)
  }
document.addEventListener("click", (event) => {
  if(url != url_parse()){
     var e = new KeyboardEvent('keypress', { 'key': 'Escape' })
     document.dispatchEvent(e)
  }
});

My idea is to simulate the keypress of Escape but this is not working.

Any ideas to improve my code is welcome or new ideas on how to close the browser's find when the user change tab (only the hash of the url change when the user change tab).

Thanks




Aucun commentaire:

Enregistrer un commentaire