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!";
cbradstreetAsked:
Who is Participating?
 
Adoryc666Commented:
You can test this.
	if (navigator.userAgent.match('Chrome')) {
		alert ("Click the \[Leave this Page\] button for Instant Download Access!");
	} else {
		alert ("Click the \[OK\] button for Instant Download Access!");
	}

Open in new window

0
 
rkeith2412Commented:
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

0
 
rkeith2412Commented:
Did my solution not work?  It seemed to work fine for me.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
MMDeveloperCommented:
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.
}
0
 
cbradstreetAuthor Commented:
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?
0
 
rkeith2412Commented:
I think this would best be addressed by using MMDeveloper's confirm idea. Then you only change the URL is they click ok.
0
 
cbradstreetAuthor Commented:
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 :-))
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.