[jQuery] How to uninstall the
<div dir="ltr"><div>I have a jQuery-based script that performs some updates on the current page (using the load method), and eventually visits a second page, by resetting window.location.
</div><div><br class="webkit-block-placeholder">
</div><div><div>This works fine, but if the user hits the back button, the whole sequence is repeated, including the re-loading of the second page.</div><div><br class="webkit-block-placeholder"></div><div>I'd like to prevent this behavior. Is it possible?</div>
<div><br class="webkit-block-placeholder"></div><div>I tried removing the script with $( 'script[src*=/path/to/script]' ).remove(), but this did not prevent the whole sequence from running again.</div><div><br class="webkit-block-placeholder">
</div><div>Then I thought that the reason for this was that using remove() does not get rid of the callback that was originally installed at the very end of the script with jQuery( MyScript.sleep ). So I tried to uninstall the callback with $( 'document' ).unbind( 'ready', ... ), but this didn't do anything either.</div>
<div><br class="webkit-block-placeholder"></div><div>How can uninstall the onready callback? If this is not possible, is there some other way that I can block the sequence from running a second time when the user the BACK button?</div>
<div><br class="webkit-block-placeholder"></div></div><div>The script has the following form:</div><div><br class="webkit-block-placeholder"></div><div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;">var MyScript = ( function ( $ ) {</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> var SELF_URL = location.pathname + location.search;</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"><br class="webkit-block-placeholder">
</span></span></span></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> var $$; $$ = {</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> check: function () {</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> if ( $$.results_ready() ) {</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> $( 'script[src*=/path/to/script]' ).remove();</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new'; font-size: 16px; font-weight: bold;"><div> $( 'document' ).unbind( 'ready', $$.sleep ); // is this right???</div></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> window.location = SELF_URL + '&results=1';</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> }</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> else {</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> $$.sleep();</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> }</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> },</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"><br class="webkit-block-placeholder">
</span></span></span></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> sleep: function () {</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> setTimeout( $$.refresh, 2000 );</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> },</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"><br class="webkit-block-placeholder">
</span></span></span></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> refresh: function () {</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> $( 'body' ).load( SELF_URL, $$.check );</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> },</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"><br class="webkit-block-placeholder">
</span></span></span></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> results_ready: function () {</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> // etc., etc.</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> }</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> };</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"><br class="webkit-block-placeholder">
</span></span></span></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"> return $$;</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;">} )( jQuery );</span></span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;"><br class="webkit-block-placeholder">
</span></span></span></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-weight: bold;">jQuery( MyScript.sleep );</span></span></span></div>
<div><br class="webkit-block-placeholder"></div></div><div><br class="webkit-block-placeholder"></div><div>
</div><div>Thanks in advance!</div><div><br class="webkit-block-placeholder"></div><div>Kynn</div><div><br class="webkit-block-placeholder">
</div><div><br class="webkit-block-placeholder"></div></div>