Monday, 15 April 2013

html - JavaScript to reload page if it is in bfcache -



html - JavaScript to reload page if it is in bfcache -

i'm trying set script browser decide if page loading comes bfcache or server. i'm 99% sure bfcache issue, because other problems i've seen of nature cite bfcache issue.

this relevant because bfcache page "freezes" state of javascript on website i'm working on (i didn't write scripts, i'm javascript amateur), , if utilize button page, scripts don't work. work fine, though, if nail refresh button.

this effort @ solving issue:

<body onload="nobfc()" onpageshow="checkcache()"> // lots of html content <script type="text/javascript"> function checkcache(){ if (cached == true){ location.reload(true);} }; var cached = ""; function nobfc(){ cachecheck = false; }; window.onunload() { cachecheck = true; }; </script>

the rationale being, whenever user navigates away page, window.onunload() set variable cached boolean "true", indicate has been cached bfcache.

then, whenever page shown 1 time again onpageshow, script checks variable. if it's "true", forces page reload value of cached set "false".

is there easy missed syntactically, or not workable solution?

try appending random query location string.

window.location = location.href + '?random=' + 1234;

javascript html

No comments:

Post a Comment