Skip to content Skip to sidebar Skip to footer

Is Is Possible To Call A Function After Window.location Has Loaded New Url?

I'd like to be able to call a jquery function once window.location has completed loading a URL. Is this possible? I can't seem to find anything online about this. for instance: i

Solution 1:

You can either use window.onload of the destination page (if you have access to modify the code of that page), or you can use window.onunload to have the alert be launched when unloading the current page. You cannot execute code on the current page after the new page has been loaded.

Solution 2:

Yes.

This page demonstrates onload/onunload behavior.

<html><head><script>window.doUnload = function(){
                alert("Here!");
            }
            window.doLoad = function(){
                window.location="http://www.google.com";
            }
        </script></head><bodyonload="doLoad();"onunload="doUnload();"></body></html>

Solution 3:

After a user logs in for the first time I need to load my index page to initialize everything but then need to forward them to another page for profile completion.

use window.location to redirect the user to your index, adding a query parameter (something like window.location=index.php?firstLogin=true ) and on your index redirect (using javascipt http 300, header() or whatever you are using) to the profile page after it ends loading if the parameter is set

Solution 4:

Iframe

One (ugly) method you could use is to instead of using window.location, clearing the body, adding an iframe with the relevant path and listening to its onload function. After that you can run code inside the iframe as long as it's not cross-site scripting.

I use this method to perform small automated scripts, that can't really on third-party plugins.

Ajax

Another method might be using ajax to load the page/body content. Then replacing your body with the newly loaded body and start executing the next functions.

Post a Comment for "Is Is Possible To Call A Function After Window.location Has Loaded New Url?"