Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't understand your response. Any idea where my question went?

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.

  • #6
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •