Implementing the SetTimeout Inline Method

I am working on a browser extension on facebook, now my problem is that facebook overrides the native setTimeout and setInterval functions, and their implementation does not work in Internet Explorer.

Is there any way to implement these features?

+4
source share
1 answer

You can create an iframe, and then get a window object to it, get a new setTimeout definition and overwrite it in your global namespace:

 var f = document.createElement('iframe'); document.body.appendChild(f); window.setTimeout = f.contentWindow.setTimeout; document.body.removeChild(f); 

Although this works, it is probably not a good idea for 2 scripts to start rewriting each other. I suggest you let FB take control of the setTimeout function and use its new copy, but do not overwrite it again (you can save it in a local var or in a global variable with a different name).

+5
source

Source: https://habr.com/ru/post/1441094/


All Articles