Last post Jan 28, 2016 07:30 AM by Zhi Lv - MSFT
Jan 05, 2016 01:13 PM|abhijithmanipal|LINK
I am facing one issue in JS i.e, once the browser is closed by the user or page is refreshed, we need to show the pop up whether the user want to continue or not.
- "You want to continue ?" with buttons "Yes" "No".
If "Yes" is clicked then go the page
If "No" is clicked then execute the some code and redirect the user to log off.
Now the browser pop up - "Are you sure to leave the page ?" is displayed once the user clicks on "No" button.
This is my code -
window.onbeforeunload = closingCode;
var message = "Are you sure you want to navigate away from this page?\n\nYou have started writing or editing a post.\n\nPress OK to continue or Cancel to stay on the current page.";
if (confirm(message)) return true;
else return false;
Any help appreciated !!
Jan 05, 2016 01:36 PM|Navin Dhananshan|LINK
I resolved one of these issue using
Jan 05, 2016 05:15 PM|abhijithmanipal|LINK
Thanks for your reply.
Above link says about displaying the pop up on condition. But what i want is to display the pop up everytime (confirm popup) -
You want to continue ?" with buttons "Yes" "No".
But when i click on "Yes" just be in the same page which happens just fine.
But on click of "No" it is displaying the browser pop up - "Are you sure to leave the page ?" , which i don't want to be displayed.
Jan 05, 2016 05:38 PM|PatriceSc|LINK
What if you don't return anything at all? (rather than false)
Usually you just return a string which comes in addition to the default browser and the browser handles as well the response.
Jan 06, 2016 03:56 AM|abhijithmanipal|LINK
Thanks for the reply.
Can you please explain bit more to understand.
Jan 28, 2016 07:30 AM|Zhi Lv - MSFT|LINK
I suggest you could check the following articles:
Although the situation you describe can be very annoying, the reasoning behind this feature is sound. Consider a site where you’re typing in a large amount or text, such as an email or filling in a long form. It could be even more annoying to inadvertently
close the window with a single click and lose all of your typing. In this case, the feature gives you a chance to go back and submit or save your work before losing it, forever. For this reason, you should think carefully about disabling this feature.