PDA

View Full Version : code to prevent exit pop-up on internal links



lsargent
Aug 19th, 2009, 11:48 PM
The exit pop-up script I have is working fine, other than the fact that it engages on any internal links as well.

I know that there is either a code that can be applied universally, or a code I can put in every link that will prevent this from happening.

Not sure that it matters, but I've included the exit script below. Any help on which code to use and where to place it in my page would be a big help.

Thanks



<script type="text/javascript">
var internal = 0;
function bunload() {
if (internal != 1) {
window.onbeforeunload = null;
alert("******************************************************\n WAIT! WAIT! WAIT! WAIT! WAIT! WAIT!! WAIT!!\n******************************************************\n\nMy partner will probably KICK MY *** for this...\n\nI am secretly giving away a LIMITED number of $20\ncoupons just for Tweeting about us.\n\nIf you act right now, you can grab our Manuscript\nplus ALL Bonuses for just $27!\n\nJust click *CANCEL* on the next window to get your\nV.I.P. discount link!\n\n******************************************************");
window.location = "gift page";
return "******************************************************\n Click CANCEL - Click CANCEL - Click CANCEL \n******************************************************\n\n Click *CANCEL* Now to get your V.I.P. discount!\n\n"; }
else {
internal = 0;
}
}
if (internal != 1) {
window.onbeforeunload = bunload;
}
else {
internal = 0;
}
</script>

_Aerospace_Eng_
Aug 19th, 2009, 11:55 PM
Add rel="external" to all of your external links. Then you can use this javascript.

<script type="text/javascript">
function bunload() {
window.onbeforeunload = null;
alert("******************************************************\n WAIT! WAIT! WAIT! WAIT! WAIT! WAIT!! WAIT!!\n******************************************************\n\nMy partner will probably KICK MY *** for this...\n\nI am secretly giving away a LIMITED number of $20\ncoupons just for Tweeting about us.\n\nIf you act right now, you can grab our Manuscript\nplus ALL Bonuses for just $27!\n\nJust click *CANCEL* on the next window to get your\nV.I.P. discount link!\n\n******************************************************");
window.location = "gift page";
return "******************************************************\n Click CANCEL - Click CANCEL - Click CANCEL \n******************************************************\n\n Click *CANCEL* Now to get your V.I.P. discount!\n\n";
}
window.onload = function()
{
var links = document.getElementsByTagName('a');
for(i = 0 ; i < links.length; i++)
{
if(links[i].getAttribute('rel') == 'external')
{
links[i].onclick = function()
{
bunload();
}
}
}
}
</script>

lsargent
Aug 20th, 2009, 12:09 AM
does it matter where i place this condition within the href code?

P.S. Thanks! that was a fast reply

_Aerospace_Eng_
Aug 20th, 2009, 12:12 AM
No just add rel="external" anywhere within the anchor element. No need for onclick to be in there anymore.

lsargent
Aug 20th, 2009, 12:24 AM
Just replaced the previous script I had and included the condition in all anchor areas, but the function won't engage upon exit, it just closes the window.

Any suggestions?

Anyway to get it to work with the script I had before?

_Aerospace_Eng_
Aug 20th, 2009, 12:52 AM
Yeah just copy and paste your original script leaving the window.onload stuff. Its not hard. It helps to try yourself you know.

<script type="text/javascript">
var internal = 0;
function bunload() {
if (internal != 1) {
window.onbeforeunload = null;
alert("******************************************************\n WAIT! WAIT! WAIT! WAIT! WAIT! WAIT!! WAIT!!\n******************************************************\n\nMy partner will probably KICK MY *** for this...\n\nI am secretly giving away a LIMITED number of $20\ncoupons just for Tweeting about us.\n\nIf you act right now, you can grab our Manuscript\nplus ALL Bonuses for just $27!\n\nJust click *CANCEL* on the next window to get your\nV.I.P. discount link!\n\n******************************************************");
window.location = "gift page";
return "******************************************************\n Click CANCEL - Click CANCEL - Click CANCEL \n******************************************************\n\n Click *CANCEL* Now to get your V.I.P. discount!\n\n"; }
else {
internal = 0;
}
}
if (internal != 1) {
window.onbeforeunload = bunload;
}
else {
internal = 0;
}
window.onload = function()
{
var links = document.getElementsByTagName('a');
for(i = 0 ; i < links.length; i++)
{
if(links[i].getAttribute('rel') == 'external')
{
links[i].onclick = function()
{
bunload();
}
}
}
}
</script>

lsargent
Aug 20th, 2009, 01:13 AM
You're right. I'm learning this stuff as I go and have been so frustrated by this process. Thanks for all the help.

rokmex
Mar 14th, 2011, 10:00 AM
Any idea of how to do this in dreamweaver?

VIPStephan
Mar 14th, 2011, 11:16 AM
Open the code view and paste the code.