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 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Problem with Exit Notice Popup - please help

    I re-wrote this code to display an exit notice alert and open a new window after user confirms they wish to leave the website.

    However, something is wrong with my code below. The alert and cancel alert works fine, but my new window link does not appear.
    I was curious if i could get some help fixing this code from anyone in the JavaScript programming forum.

    See code:

    <script language='JavaScript'>
    function ExitNotice() {
    if(confirm("You are now leaving the web site. To leave our site for the link you selected, click OK. Or Click Cancel to remain. Thank you for visiting our site.")) { return true;
    }
    history.go(0);
    return false;
    }
    </script>

    Now for my button code that appears later inside my form which opens a sized window.

    <input id="btnView" class="MyButton" type="button" onclick="ExitNotice('http://www.google.com', null, 'left=40,top=100,height=550,width=780, status=no,toolbar=no,menubar=no,location=no, resizable=yes, scrollbars=yes')" name="btnView" value="View Web Site" />


    Please test and advise what i'm missing... thanks in advance as i eagerly wait for a solution that fixes this issue.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Makes no sense.

    The ExitNotice() function as you coded it takes *NO* parameters.

    Yet when you call it from the onclick, you pass THREE arguments.

    Those arguments are just a waste of coding time and space.

    But in any case, if you opened a new window with those properties, the user would *NOT* leave your website. They would just have *ANOTHER* window on the screen with the new website.

    Make up your mind.
    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.

  • #3
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Yes,
    I am aware of the issues... thats why i'm posting the problem i'm having...this code worked as a link however i modified it to work with an input button. I'm trying to search for a code snippet or sample showing me exactly how i can resolve this issue. If i could get someone to post their code solution, to accomplish an Exit Notice that produces a sized window from an input button, that would be a great help.

    Clear Code samples to solution welcomed.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Okay, but I still don't see the need for the confirm( ) call, since the user isn't *really* leaving the site, at all. But I'll leave it there.
    Code:
    <script type="text/javascript">
    function ExitNotice(url, windowname, windowstyle) 
    {
        // try to find a more appropriate message!
        var msg = "You are now leaving the web site.\n"
                + "To leave our site for the link you selected, click OK.\n"
                + "Or Click Cancel to remain.\n\n"
                + "Thank you for visiting our site.";
        if ( ! confirm( msg ) ) return false; // or just "return"...the false is doing nothing
    
        window.open( url, windowname, windowstyle );
        return true; // or just "return"...the true is doing nothing
    } 
    </script>
    And then your <input type=button> should be fine, as is, though it really does not need either an id or a name, since neither will ever be used.
    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
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Wow... i think we GOT IT!!! The Code appears to work like a charm!
    What do you think?
    Code:
    <html>
    <head>
    <title>Exit Notice Test</title>
    <script type="text/javascript">
    function ExitNotice( url, windowname, windowstyle) 
    {
        // This leaving site noticed was required by management. To explain the reason, is well... complicated.
        var msg = "You are now leaving the web site.\n"
                + "To leave our site for the link you selected, click OK.\n"
                + "Or Click Cancel to remain.\n\n"
                + "Thank you for visiting our site.";
        if ( ! confirm( msg ) ) return false; // or just "return"...the false is doing nothing
    
        window.open( url, windowname, windowstyle );
        return true; // or just "return"...the true is doing nothing
    } 
    </script>
    </head>
    
    <body>
    <form>
    <input class="MyButton" type="button" onclick="ExitNotice('http://www.google.com','MyWindow','left=40,top=100,height=550,width=780, status=no,toolbar=no,menubar=no,location=no, resizable=yes, scrollbars=yes')" value="View External Web Site" />
    </form>
    </body>
    </html>
    YOUR HELP WAS GREATLY APPRECIATED!... THANK YOU "Old Pedant" Does this work for you as well? IE AND Firefox appear to accept the code without errors.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    That's dead-easy, very old style, JavaScript code. It would have worked way back in MSIE 4 and Netscape 4, maybe before. Should not be any modern browser that doesn't support it (unless the user turns off JavaScript, of course).
    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.

  • #7
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can you do the same thing without the button?

    Hello. I am looking at creating something similar for a particular client...

    So no button, but instead if a user closed the browser window, they would get the popup notice asking them if they really want to leave and, if not, they could click cancel and be taken to another web page.

    Possible? If so, can you explain the proper code?

    Thanks!

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by disneeze View Post
    Hello. I am looking at creating something similar for a particular client...

    So no button, but instead if a user closed the browser window, they would get the popup notice asking them if they really want to leave and, if not, they could click cancel and be taken to another web page.

    Possible? If so, can you explain the proper code?

    Thanks!
    Code:
    <script type = "text/javascript">
    window.onbeforeunload = confirmExit;
    function confirmExit()  {
    return "Message to display in dialog box";
    }
    </script>
    But it is for the user to decide whether he wishes to close the browser window, and you cannot prevent this.

    Remember that the window.onbeforeunload event is fired every time the page is about to unload. This means that if the user clicks "refresh" or a button on your page, and your page posts back to the server, the window.onbeforeunload event will fire.

    This sort of prompt tends to annoy the user, and should be avoided unlesss it really adds value.
    Last edited by Philip M; 12-12-2009 at 08:41 AM.

  • #9
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Phillip!

    I found a similar script here that does exactly what I want to do.

    However, I'm looking at customizing the "Are you sure you want to navigate away from this page?" or not having it all and just having my custom message.

    Think this is possible?

  • #10
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by disneeze View Post
    However, I'm looking at customizing the "Are you sure you want to navigate away from this page?" or not having it all and just having my custom message.

    Think this is possible?
    No, the onbeforeunload message cannot be suppressed or changed. (Pretty obviously for security reasons). All you can do is add you own custom message.


  •  

    Posting Permissions

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