views:

58

answers:

1

I'm working with some code that uses JQuery's $(document).ready functionality to set up a jqGrid instance. It appears that the code is fired even when returning to the page via a back-button click.

In a stripped-down test page, a similar ready function is not called when reached via a back-button click:

<html>
<head>
    <script type="text/javascript" src="/JQuery/jquery-1.4.2.min.js"></script>

    <script type="text/javascript">

    $(document).ready(function(){
        alert('ready');
    })

    </script>
</head>
<body>
    <p>Index View</p>

    <a href="detail.html">Detail</a>
</body>
</html>

Can you give me some hints of where to look for what is causing this difference in behavior?

I found some related information in an answer to this question, but the page with the overactive ready event doesn't have an event handler registered for unload.

A: 

I think you might be able to find your answers over here: http://stackoverflow.com/questions/158319/cross-browser-onload-event-and-the-back-button

The behavior seems to depend a bit on the browser (IE vs. Non-IE) and the version of jQuery (v1.4+ behaves differently than older versions). It's essentially related to how each browser implements its "bfcaching" as Mozilla calls it -- the back/forward button caching. Check out the links in the post I mentioned.

Cory Larson