Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-06-2012, 05:34 PM   PM User | #1
notacoder
New to the CF scene

 
Join Date: Nov 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
notacoder is an unknown quantity at this point
Pop Up Message Please Help ASAP

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...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=sprin g2&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!

Last edited by notacoder; 11-06-2012 at 10:38 PM..
notacoder is offline   Reply With Quote
Old 11-06-2012, 07:43 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Google for onbeforeunload();

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

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 11-06-2012, 10:47 PM   PM User | #3
notacoder
New to the CF scene

 
Join Date: Nov 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
notacoder is an unknown quantity at this point
I don't understand your response. Any idea where my question went?
notacoder is offline   Reply With Quote
Old 11-06-2012, 11:35 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 11-06-2012, 11:39 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 11-07-2012, 04:13 PM   PM User | #6
notacoder
New to the CF scene

 
Join Date: Nov 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
notacoder is an unknown quantity at this point
Quote:
Originally Posted by Old Pedant View Post
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.
notacoder is offline   Reply With Quote
Old 11-07-2012, 08:28 PM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
No no no... You just now need to add a bit of logic to your code!

Add a global flage:
Code:
<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:
Code:
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?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:13 AM.


Advertisement
Log in to turn off these ads.