Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exit Pop-up

Status
Not open for further replies.

caconner

Technical User
May 20, 2002
42
US
I'm a total novice when it comes to cookies and not much better off with JavaScript, but unfortunately I think I need both to satisfy a request for the Internet site I'm working on.

I need to have a pop-up window display only when a user clicks a link on our site that takes them to a site external to ours. It does not need to pop when someone is clicking links that keep them within the site.

To further complicate the request, the pop up should contain a checkbox so that they can choose not to see the warning again. And yes, to further complicate things, it needs to display for each external link. If they click external link A and check the box not to display again, re-enter the site and click external link B, the pop-up will display again since its a different site.

Any suggestions would be a tremendous help!
 
well...judging from what you wrote:

a. user clicks on links, but stays within your site - nothing happens.

b. user clicks on link that takes them to new site, warning fires off "leaving this site" or whatever.

c. same user comes back to original website (yours) and clicks new out-of-site link, new warning

there are a few questions:

1. when the user clicks the link to take them somewhere else, does the new site have it's own window, or does it consume the current window in which the link was clicked?

2. does the warning have an 'abort' clause to it? meaning, is the warning an acknowledgement or a question..."you are leaving" vs. "do you want to leave"

3. do the number of links ever change, without you knowing?

here would be my suggestion if the following answers to the above questions are 1-same window, 2-acknowledge, 3-no:

have a main .js file (external) that you have variables you will set. you count the number of away links (diff site links) and make the corresponding number of variables...

ex.
<script>
//for 3 away links;
awayLink1=1;
awayLink2=1;
awayLink3=1;

function setLinkAlert(x) {
if (x=='aLink1") {
if (awayLink1!=0) {alert(msg);}
location.href=' }
//repeat above for all away links 2&3
}
</script>

the '0' is a basic binary structure for your 'see alert' checkboxes. 0 is no, 1 is yes.

create your links using functions:

<a href="javascript:setLinkAlert(id)"; id=aLink1>here is away link 1</a>

then on your checkboxes, you run a function if checked to turn that corresponding awayLink variable to a '0', so that when the script checks that variable it will say 'no, don't show the message'...this way, each away link will have it's own message condition.

as for the cookie part of the deal, each time a checkbox is clicked, in addtion to the setting of the variable, you would update the cookie saved on the user computer. you could easily save the cookie info as pairs, similar to:

awayLink1=0;awayLink2=1;awayLink3=0 etc.

hope this helps.

- g
 
In answer to your questions:
1. I was going to fire off the pop-up in a new window. Then once the user clicks the OK button, the external link would open in that pop-up window. The original website window would stay open in the background.
2. Answered in #1, but for redundancy... I wasn't necessarily concerned with giving them an option to change their mind. Since it's a new window, they can just close it and our site will still be in the background.
3. No, the number of links will not change. Unless I'm the one that does it anyway.

I like the external .js file since these links will be on every page (embedded into the footer). Does it make sense to only set a cookie if the checkbox is checked? Then if the cookie isn't found the next time around the pop-up will continue to fire?

To set a cookie to never expire do you just set some unrealistic date into the future?

Have I given away how little I know about either of these subjects? Thanks for the direction!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top