Javascript loading after redirect

in my Javascript code I load a page and then I would like to perform some functions. I tried to use solutions such as window.onload, but this happens after my html is loaded (blank page with only JS), I need a function to execute after loading the page that I am loading. I am using this code:

this.document.location.href = myurl;

And after these loads, I would like to call some function. Is there any way to do this? Thanks

EDIT:

I cannot edit the source code of the landing page.

+4
source share
3 answers

When you change the value document.location.href, you are essentially doing a redirection.

, , , xhr , , , , , .. , .. script, .

: , - - , , , . , , iframe, , , -

+3

'window.onload = myFunction() {...}' , .

this.document.location.href , , onload- script . , document.location = myUrl . Document-API Mozilla

0

window.load leaves forever, because he is waiting for the loading of all the images and assets on the page.

It seems that the best solution for you would be to ask you to complete a document download. Here is a simple example:

(function poll(){
    if(document.readyState === "complete"
    {
        // Your code here
    }
    else
        setTimeout(poll,500);
})();
0
source

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


All Articles