• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2908
  • Last Modified:

how to cancel onunload or onbeforeunload event?

I want to be able to check if F5 is pressed, so that I can cancel refresh and call another function..

I tried with:

document.onkeydown = checkRefresh;

function  checkRefresh(){
    if (event.keyCode == 116) {
        myRefreshFunction();
        event.returnValue = false;
        return;
    }
}

but, myRefreshFunction() is not called and refresh still happens?!
0
mileage
Asked:
mileage
1 Solution
 
cubrovicCommented:
What is in myRefreshFunction.
Maybe problem is there.
0
 
jonnalCommented:
try


function  checkRefresh(){
   if (event.keyCode == 116) {
       myRefreshFunction();
       return false;
   }
}
0
 
jaysolomonCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: jonnal {http:#8227315}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now