0

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!

enne87
  • 2,221
  • 8
  • 32
  • 61
  • 1
    possible duplicate of [Can I run javascript before the whole page is loaded?](http://stackoverflow.com/questions/2920129/can-i-run-javascript-before-the-whole-page-is-loaded) – Sinan Samet Apr 28 '14 at 08:00

2 Answers2

1

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");
});
paulitto
  • 4,585
  • 2
  • 22
  • 28
1

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.

Amir Popovich
  • 29,350
  • 9
  • 53
  • 99