Is It possible to call a user defined JS function when the page refresh button is clicked? I want to call a reload function, if yes is clicked I want the user to logout. Below is my code I used. but am getting a different confirmation pop up which reloads the page. I am nor able to call my custom function. Below is my code window.onbeforeunload = function() { var r=confirm("Do you want to leave page!"); if (r) { //write redirection code sessLogOut(); } else { //do nothing } };
Asked
Active
Viewed 143 times
-1
-
2Hi and Welcome to SO @Jeyalakshmi, please read the [tour] before asking. – Sagar V Mar 23 '17 at 11:52
-
2Possible duplicate of [How do I detect a page refresh using jquery?](http://stackoverflow.com/questions/8013429/how-do-i-detect-a-page-refresh-using-jquery) – Exception_al Mar 23 '17 at 11:55
-
I used. but am getting a different confirmation pop up which reloads the page. I am nor able to call my custom function. Below is my code window.onbeforeunload = function() { var r=confirm("Do you want to leave page!"); if (r) { //write redirection code sessLogOut(); } else { //do nothing } }; – jeya lakshmi Mar 23 '17 at 12:20
1 Answers
0
A good solution for you may be using this in your html:
<body onunload="pageUnload()">
and this in JS:
function pageUnload(){
if(confirm("Do you want to leave page!")){
// DO SOMETHING
} else {
// DO NOTHING
}
}

jsadev.net
- 2,800
- 1
- 16
- 28
-
I used. but am getting a different confirmation pop up which reloads the page. I am nor able to call my custom function. Below is my code window.onbeforeunload = function() { var r=confirm("Do you want to leave page!"); if (r) { //write redirection code sessLogOut(); } else { //do nothing } }; – jeya lakshmi Mar 23 '17 at 12:19
-