...

View Full Version : Pop Up Message Please Help ASAP



notacoder
11-06-2012, 06:34 PM
I need to create a pop up message that informs website viewers that they are leaving our site.

I have this in the header.

<script>
function leaveCheck(url) {
if(confirm("You are being redirected from our website and we are not responsible for transactions or services beyond this point."))window.open(url)
}
</script>


And I have the onlick reference on the link leaving our site which looks like this,
<a onclick="leaveCheck(this.href); return false" target="_blank" href="http://www.google.com">


This works great but the problem I have is we have a AccuWeather widget on our website and I can’t seem to make the pop up work on the link going back to AccuWeather.

Here is the code for the AccuWeather widget on our page.

<div style='width: 180px; height: 150px; background-image: url( http://vortex.accuweather.com/adcbin/netweather_v2/backgrounds/spring2_180x150_bg.jpg ); background-repeat: no-repeat; background-color: #607041;' ><div id='NetweatherContainer' style='height: 138px;' ><script src='http://netweather.accuweather.com/adcbin/netweather_v2/netweatherV2ex.asp?partner=netweather&tStyle=normal&logo=1&zipcode=61001&lang=eng&size=8&theme=spring2&metric=0&target=_blank'></script></div><div style='text-align: center; font-family: arial, helvetica, verdana, sans-serif; font-size: 10px; line-height: 12px; color: #FDEA11;' ></div></div>

Any suggestions on how to get a pop up message stating you are leaving our site when clicking on the AccuWeather link?

We have a State IT Audit going on and i'd like to get it fixed before they leave this week. Otherwise i'll have to remove it completely.

Thanks!

Philip M
11-06-2012, 08:43 PM
Google for onbeforeunload();

It is your responsibility to die() if necessary….. - PHP Manual

notacoder
11-06-2012, 11:47 PM
I don't understand your response. Any idea where my question went?

Old Pedant
11-07-2012, 12:35 AM
Ummm...there's no "link" there for the accuweather thing.

There may be one, but it's being generated internally to that <script> you are getting from accuweather.

Under these circumstances, it would be tough [not impossible] to alter the link.

As Philip said, google for "onbeforeunload". It's a method on the window object that allows you to intercept the unload (change to another page) before it actually happens and give the user a chance to cancel his/her choice to leave the page.

Old Pedant
11-07-2012, 12:39 AM
Ahhh...and I looked at the code that <script> tag produces: The accuweather is actually embedding a flash player on your page, not just JavaScript, and the link to their site is apparently made via the Flash code. So you couldn't intercept the link to their site via JS, anyway.

onbeforeunload is probably the only choice.

notacoder
11-07-2012, 05:13 PM
Ahhh...and I looked at the code that <script> tag produces: The accuweather is actually embedding a flash player on your page, not just JavaScript, and the link to their site is apparently made via the Flash code. So you couldn't intercept the link to their site via JS, anyway.

onbeforeunload is probably the only choice.


I got the onbeforeunload to work but unfortunately it fires on every link internal or external which will not work. I may have to remove the weather widget.

Thanks for all of your suggestions.

Old Pedant
11-07-2012, 09:28 PM
No no no... You just now need to add a bit of logic to your code!

Add a global flage:


<script type="text/javascript">
var okayToExit = false;
</script>

Now, in *ALL* the place where you have your current prompting you just set that flag to true:


function leaveCheck(url) {
if(confirm("You are being redirected ...")
{
okayToLeave = true;
window.open( url );
}
}


And, finally, in your onbeforeunload code, you look at that flag: If it is true, you allow the unload to happen without intervening. (You also RESET the flag to false, so it is ready for the next attempt to leave the page.)

See?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum