Can I wait for location.href to load a page?

Is it possible to know when a page has loaded using location.href? My current code looks like this and I want to trigger some events to happen once my page has finished loading. I tried using $.get but it breaks my current implementation of jquery address so this won’t work.$(‘.search’).click(function() location.href = …

via PHP Website Development » Search Results » ajax:

Can I wait for location.href to load a page?

Is it possible to know when a page has loaded using location.href? My current code looks like this and I want to trigger some events to happen once my page has finished loading. I tried using $.get but it breaks my current implementation of jquery address so this won’t work.
$(‘.search’).click(function()
location.href = “/search.php”;
// trigger event here…
return false;
);This will NOT work for my current setup:
$.get(‘search.php’, function()
alert(‘Page has finished loading’);
);Are there any other options?
………………………………….

Have you tried this:
$(document).ready(function ()
alert(‘Page has finished loading’);
);EDIT: Removed second portion of answer since the purposeful redirect negates it’s usefullness
………………………………….

Once you change your location, your page unloads. You cannot run script after doing so. All you can do is detect when the new page has loaded within the new page as @DJ Quimby’s answer describes.
An exception is if you change your hash location but stay within the same document. That can be bound to an event using jQuery.
………………………………….

That will simple redirect the browser…
You want to use…
$.ajax( … );Call using jQuery to call search.php and you can then load the results into a div or something.

For more info: Can I wait for location.href to load a page?

PHP Website Development » Search Results » ajax

Can I wait for location.href to load a page?

Share this post:

Related Posts

Leave a Comment