Link to home
Start Free TrialLog in
Avatar of cbradstreet
cbradstreet

asked on

Alert box [ok] and [cancel] buttons

I have the following code to display an alert box if/when
the user leaves the current window:

--------------------------------------------------------------------
<head>

<script type='text/javascript'>
<!--
var NoExitPage = false;
function ExitPage() {
if(NoExitPage == false)      {
NoExitPage=true;
location.href='https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SSPZQ8R2T7238';

return"***************** WAIT! - HUGE DISCOUNT! *****************\n\n"+
"If you wanted the complete reseller package to *9* turnkey\n"+
"products worth $997, but the price of $27 was just a bit out\n"+
"of reach for you, then I can offer you the exact same offer\n"+
"you just passed up, but with a huge discount ...\n\n"+
"You will receive the exact same reseller package to *9*\n"+
"turnkey products worth $997 for the lowest introductory\n"+
"cost of only $17!\n\n"+
"Click the \[OK\] button for Instant Download Access!";
}
}
// -->
</script>

</head>

<body onBeforeUnload="return ExitPage();">
--------------------------------------------------------------------

Since most browsers display an [OK] and [Cancel] button
inside alert boxes, BUT Google Chrome displays [Leave this
Page] and [Stay on the Page] instead, can an expert kindly
modify the javascript to allow for either circumstance?

So, if the user is using Firefox or IE, then show as:

"Click the \[OK\] button for Instant Download Access!";

But if the user is using Google Chrome, then show as:

"Click the \[Leave this Page\] button for Instant Download Access!";
ASKER CERTIFIED SOLUTION
Avatar of Adoryc666
Adoryc666

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try this


<script type='text/javascript'> 
<!--
var NoExitPage = false;
function ExitPage() {
if(NoExitPage == false)      {
NoExitPage=true;
var btnText = "\[OK\]";
location.href='https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SSPZQ8R2T7238';
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if (is_chrome){ btnText = "\[Leave this Page\]"; }
return"***************** WAIT! - HUGE DISCOUNT! *****************\n\n"+
"If you wanted the complete reseller package to *9* turnkey\n"+
"products worth $997, but the price of $27 was just a bit out\n"+
"of reach for you, then I can offer you the exact same offer\n"+
"you just passed up, but with a huge discount ...\n\n"+
"You will receive the exact same reseller package to *9*\n"+
"turnkey products worth $997 for the lowest introductory\n"+
"cost of only $17!\n\n"+
"Click the "+btnText+" button for Instant Download Access!";
}
}
// -->
</script>

Open in new window

Did my solution not work?  It seemed to work fine for me.
I think the better solution would be to use the confirm() functionality

ret = confirm("blah blah blah");
if (ret) {
      //user clicked positively
}
else {
      //user clicked negatively.
}
Avatar of cbradstreet
cbradstreet

ASKER

rkeith2412, your solution works really well for Chrome and IE browsers, but if I test on Firefox, the alert box comes up which is good, but before I have a chance to click OK or Cancel, I am directed to https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SSPZQ8R2T7238

Any ideas?
I think this would best be addressed by using MMDeveloper's confirm idea. Then you only change the URL is they click ok.
Would you mind modifying your script to include the

ret = confirm("blah blah blah");
if (ret) {
      //user clicked positively
}
else {
      //user clicked negatively.
}

This is a little over my head :-)

Many thanks!!!!

Chantelle :-))