1

I have a page-a where I offer something for $10 , when the user tries to leave the page, I would like to ask them if they want same thing for $5.

So using onunload I could show a confirmation box with my message using this code.

function goodbye(e) {
if(!e) e = window.event;
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = 'Hey Wait, Get everything mentioned below for $5, Click on Stay on this page?'; //This is displayed on the dialog

//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
    e.stopPropagation();
    e.preventDefault();


 }
}
window.onbeforeunload=goodbye;

Now when the user clicks on Stay on this page, I want the page to redirect to page-b where same thing is available for $5.

Can anyone help me where do I have to write extra lines of codes ? I did quick research but could not find any help.

Thank you in advance.

Dipendra Pokharel
  • 508
  • 1
  • 5
  • 15
  • There is nothing returned, I think that your only option is to set a timer, and if it does fire after some time, then it means that the user is still on the page – Kaiido Oct 31 '15 at 08:31
  • Something like that: http://stackoverflow.com/a/16824414/1414562 ??? – A. Wolff Oct 31 '15 at 08:33

0 Answers0