$(document).ready() not firing after redirect with window.location
I have read the other questions
jQuery $(document).ready() not firing after window.location.href
jQ开发者_运维知识库uery $(document).ready() not firing
Why is $(document).ready not firing for me?
yet none of the solutions seem to work...
My issue is that the jQuery $(document).ready() is not firing in Firefox yet fires in other browsers after the redirect. I know the js gets loaded since it has a time variable appended to the end to keep it from caching.
I have tried using $(window).load() to the same result. Firebug is not showing errors and is showing the script being loaded, however a breakpoint placed on the ready() function never triggers.
Are there some sort of security restrictions in Firefox that could be causing the issue and if so how would I get around them?
I've been having the same problem when using back/forward. If you're not having this problem with back/forward it's probably a typo. But it could be weird behavior from Firefox.
Here's a simple example that doesn't work for me with the back button (i.e. no event fires, redirects are not involved):
<!DOCTYPE html>
<html>
<head>
<title>Simplest JQuery</title>
<script type="text/javascript" src="jquery-1.6.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
alert("document.ready");
});
</script>
</head>
<body>
<div>
Firefox will not fire document ready on back/forward navigation. Except when it
does.<br />
<a href="navigate-nowhere.html">Go!</a>
</div>
</body>
</html>
Firefox is definitely showing some bugs as I'm getting different behavior from the same code on different machines. With an up-to-date FF5 it doesn't work on Windows 7 or Leopard. I have another machine on Snow Leopard where it works like it says on the tin.
The problem isn't JQuery either - even dropping it and using addEventListener has no effect. Using the inline event (i.e. via onload in the body tag) has no effect. The "empty unload" trick documented here isn't working either.
Nor is it a problem with extensions - I've tried turning them all off. I tried a clean installation on the Leopard machine without any change.
Interestingly, the focus/onfocus event does work - unless the link is still highlighted in the page. In which case, the window.onblur event does fire afterwards, but only when using tab to change the focus.
Until I can find a better alternative, <body onUnload="">
works for me in FF5. I think your problem might go a little beyond this fix?
精彩评论