...

View Full Version : Problem with Exit Notice Popup - please help



RegGFX
11-30-2009, 07:10 PM
I re-wrote this code to display an exit notice alert and open a new window after user confirms they wish to leave the website.

However, something is wrong with my code below. The alert and cancel alert works fine, but my new window link does not appear.
I was curious if i could get some help fixing this code from anyone in the JavaScript programming forum.

See code:

<script language='JavaScript'>
function ExitNotice() {
if(confirm("You are now leaving the web site. To leave our site for the link you selected, click OK. Or Click Cancel to remain. Thank you for visiting our site.")) { return true;
}
history.go(0);
return false;
}
</script>

Now for my button code that appears later inside my form which opens a sized window.

<input id="btnView" class="MyButton" type="button" onclick="ExitNotice('http://www.google.com', null, 'left=40,top=100,height=550,width=780, status=no,toolbar=no,menubar=no,location=no, resizable=yes, scrollbars=yes')" name="btnView" value="View Web Site" />


Please test and advise what i'm missing... thanks in advance as i eagerly wait for a solution that fixes this issue.

Old Pedant
11-30-2009, 08:17 PM
Makes no sense.

The ExitNotice() function as you coded it takes *NO* parameters.

Yet when you call it from the onclick, you pass THREE arguments.

Those arguments are just a waste of coding time and space.

But in any case, if you opened a new window with those properties, the user would *NOT* leave your website. They would just have *ANOTHER* window on the screen with the new website.

Make up your mind.

RegGFX
11-30-2009, 09:01 PM
Yes,
I am aware of the issues... thats why i'm posting the problem i'm having...this code worked as a link however i modified it to work with an input button. I'm trying to search for a code snippet or sample showing me exactly how i can resolve this issue. If i could get someone to post their code solution, to accomplish an Exit Notice that produces a sized window from an input button, that would be a great help.

Clear Code samples to solution welcomed.

Old Pedant
11-30-2009, 09:43 PM
Okay, but I still don't see the need for the confirm( ) call, since the user isn't *really* leaving the site, at all. But I'll leave it there.


<script type="text/javascript">
function ExitNotice(url, windowname, windowstyle)
{
// try to find a more appropriate message!
var msg = "You are now leaving the web site.\n"
+ "To leave our site for the link you selected, click OK.\n"
+ "Or Click Cancel to remain.\n\n"
+ "Thank you for visiting our site.";
if ( ! confirm( msg ) ) return false; // or just "return"...the false is doing nothing

window.open( url, windowname, windowstyle );
return true; // or just "return"...the true is doing nothing
}
</script>


And then your <input type=button> should be fine, as is, though it really does not need either an id or a name, since neither will ever be used.

RegGFX
11-30-2009, 10:55 PM
Wow... i think we GOT IT!!! The Code appears to work like a charm!
What do you think?


<html>
<head>
<title>Exit Notice Test</title>
<script type="text/javascript">
function ExitNotice( url, windowname, windowstyle)
{
// This leaving site noticed was required by management. To explain the reason, is well... complicated.
var msg = "You are now leaving the web site.\n"
+ "To leave our site for the link you selected, click OK.\n"
+ "Or Click Cancel to remain.\n\n"
+ "Thank you for visiting our site.";
if ( ! confirm( msg ) ) return false; // or just "return"...the false is doing nothing

window.open( url, windowname, windowstyle );
return true; // or just "return"...the true is doing nothing
}
</script>
</head>

<body>
<form>
<input class="MyButton" type="button" onclick="ExitNotice('http://www.google.com','MyWindow','left=40,top=100,height=550,width=780, status=no,toolbar=no,menubar=no,location=no, resizable=yes, scrollbars=yes')" value="View External Web Site" />
</form>
</body>
</html>


YOUR HELP WAS GREATLY APPRECIATED!... THANK YOU "Old Pedant" Does this work for you as well? IE AND Firefox appear to accept the code without errors.

Old Pedant
11-30-2009, 10:58 PM
That's dead-easy, very old style, JavaScript code. It would have worked way back in MSIE 4 and Netscape 4, maybe before. Should not be any modern browser that doesn't support it (unless the user turns off JavaScript, of course).

disneeze
12-11-2009, 08:53 PM
Hello. I am looking at creating something similar for a particular client...

So no button, but instead if a user closed the browser window, they would get the popup notice asking them if they really want to leave and, if not, they could click cancel and be taken to another web page.

Possible? If so, can you explain the proper code?

Thanks!

Philip M
12-12-2009, 09:20 AM
Hello. I am looking at creating something similar for a particular client...

So no button, but instead if a user closed the browser window, they would get the popup notice asking them if they really want to leave and, if not, they could click cancel and be taken to another web page.

Possible? If so, can you explain the proper code?

Thanks!


<script type = "text/javascript">
window.onbeforeunload = confirmExit;
function confirmExit() {
return "Message to display in dialog box";
}
</script>

But it is for the user to decide whether he wishes to close the browser window, and you cannot prevent this.

Remember that the window.onbeforeunload event is fired every time the page is about to unload. This means that if the user clicks "refresh" or a button on your page, and your page posts back to the server, the window.onbeforeunload event will fire.

This sort of prompt tends to annoy the user, and should be avoided unlesss it really adds value.

disneeze
12-12-2009, 10:38 PM
Thanks Phillip!

I found a similar script here (http://www.andysowards.com/blog/tutorials/easy-javascriptajax-exit-pop-up-script-creates-div-overlay-on-page-exit/) that does exactly what I want to do.

However, I'm looking at customizing the "Are you sure you want to navigate away from this page?" or not having it all and just having my custom message.

Think this is possible?

Philip M
12-13-2009, 10:00 AM
However, I'm looking at customizing the "Are you sure you want to navigate away from this page?" or not having it all and just having my custom message.

Think this is possible?

No, the onbeforeunload message cannot be suppressed or changed. (Pretty obviously for security reasons). All you can do is add you own custom message.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum