B
B
best_kot32017-05-29 20:27:24
JavaScript
best_kot3, 2017-05-29 20:27:24

Does it stop tracking keys after updating the frame?

spoiler
top.frames['main'].onkeydown = function(e) {
      if (active==1)
      {
        e = e || window.event;
        if(e.keyCode==data.key_hil_cmp && e.altKey==true)
        {
          //тут действия
        }else if (e.keyCode==data.key_boy_cmp && e.altKey==true)
        {
            //тут действия
        }else if (e.keyCode==data.key_hp && e.altKey==true)
        {
            //тут действия
        }else if (e.keyCode==data.key_wp && e.altKey==true)
        {
            //тут действия
        }else if (e.keyCode==data.key_all && e.altKey==true)
        {
            //тут действия
        }
      }
        ///////////////
    }


there is a site on which there are several frames, so my extension monitors button presses on the site and displays additional functions when a key combination is pressed, so everything works until the frame is updated, let's say a transition to another page inside the frame. other functions continue to work. this code is in the content script, it doesn't load on the page and works directly from there. tell me how to fix it? without uploading the code to the site... it helps to go into the extension settings, turn off the keystroke check, and then turn it back on and everything will work until the frame is updated
UPD: I did not find a suitable solution, all solutions work 1 time when loading, the only way out was to add a check to the interval, I used location because frames on the site are loaded by the location.href method and there is no scr property, but there it was possible through it, and therefore searsh. the frame after the address has a load time, and therefore even if the frame is simply updated, the time will change and it will run the desired code. You can also use MutationObserver inside the function that is called by the interval.
spoiler
setInterval(refresh,500);
var set;
function refresh(){
  if (set!=top.frames['main'].location.search)
  {
    set=top.frames['main'].location.search;
    ///ну и тут код
  }
  
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question