code show as below:
$(document).bind("keydown", function (e) { // Document binding keyboard down event e = window.event || e; // Solve browser compatibility issues if (e.keyCode == 116 ) { // Press F5 var delIsHidden = $("#delete_pop").is(":hidden" ); var notSaveIsHidden = $("#not_save_pop").is(":hidden" ); // Display popup Now , disable F5 to refresh if (delIsHidden == false || notSaveIsHidden == false ) { e.keyCode = 0; return false; } else { // Let refresh and delete the session of the large screen sessionStorage.removeItem("five screen" ); } } });
Notice:
- The purpose of this is to prohibit users from refreshing the browser through F5 if the content of the web page is not loaded. This method is not very good and should not restrict users too much.
- For old browsers, there is no need to be compatible with it , and it should be eliminated. (except specific users)