简体   繁体   中英

Javascript - Detect page reload before document was fully loaded

I'd like to find out if a user presses F5 in a web browser before the page was fully loaded. I would like to use this as an indicator to find out if the page load time was too high for the user.

Is there a possibility?

Thanks much!

with jQuery you can do something like this

var pageLoaded = false;

$(window).load(function(){
   pageLoaded = true;
});

$(document).on('keyup', function(e){
  if (!pageLoaded && e.keyCode == 116)
         alert("f5 pressed before page fully loaded");
});

You can use the before unload event and save info somewhere:

$(window).bind('beforeunload',function(){
     //save info 
});

just notice, that this event will invoke when you close the browser as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM