Execute code when page load ready or page is being visible through back button
I was wondering, how I can use JQuery, to execute a same code, when either a page is loaded ready, or a page is visible to user due to back button clicked?
$(document).ready(function(){
// Work only first time page loading.
// How about when user click on back button and come to this HTML page?
alert('You c thi开发者_运维百科s page, as it is either first time loading, or user click on back button');
});
One thing to note (that might break your functionality). Opera often does not unload your site when you leave it, so when you hit back, it does not execute the javascript code again.
If i were you, i would use this: http://www.electrictoolbox.com/jquery-cookies/
By doing this, you can tell if its the users first time visit or not :)
This depends on how your browser handles it. Some browsers reload the page (which would work how you want it) and some others display an older version of it (which does not trigger DOM-ready). I do not think that there is a reliable method.
Have you tryd using pageLoad() instead of the $(document).ready function of jquery.
精彩评论