Results 1 to 11 of 11
  1. #1
    Star Lounger
    Join Date
    Feb 2003
    Location
    DC Metro, District Of Columbia, USA
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    confirm() cancel and other js issue

    I am having issues (read fits, angst, other) with the confirm() not canceling when the cancel button is selected. Basically, if the viewer is clicking on a link to an external site, I use onclick to call the exit function which asks = confirm("Click yes to leave the site. Click Cancel to stay on the site"). Both buttons open the link! I capture the boolean t/f in a var and if t, then a good bye message, else window.alert("You are still on the site"); window.location.reload();
    Now, not only does the cancel not cancel, the reload won't reload, even with reload(forceget) or reload(true). ¡¡¡AAAAAAARRRRRRRRRRRRGGGGGGGGGGGGHHHHHHHHHHHHh !!!

  2. #2
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: confirm() cancel and other js issue

    On the True return have you tried a small function such

    <pre>
    <script type="text/javascript">
    function ExitFunc(){
    if

    ...my code

    return true;
    }
    else{
    alert("Your Still here");
    return false;
    }

    </script>
    </head>


    </pre>


    This will allow you to return a state on the onsubmit, like so (assuming the links are within a form of course <img src=/S/grin.gif border=0 alt=grin width=15 height=15>)

    <pre><form name="form1" method="post" action="" onsubmit="return checkForm(this)">
    </pre>

    Jerry

  3. #3
    Star Lounger
    Join Date
    Feb 2003
    Location
    DC Metro, District Of Columbia, USA
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: confirm() cancel and other js issue

    here is my code:
    Virginia Department of Game and Inland Fisheries
    onclick calls exitsite
    <script language="JavaScript">
    function exitsite()
    {
    var exiting = window.confirm("Click OK to leave the site. Click Cancel to stop.");
    //document.write(exiting);
    if (exiting)
    {
    window.alert("You are leaving a Fort Belvoir Army web site." + 'n' + "The appearance of hyperlinks does not constitute endorsement by the U.S. Army of this web site or the information, products or services contained therein. For other than authorized activities such as military exchanges and Morale, Welfare and Recreation sites, the U.S. Army does not exercise any editorial control over the information you may find at these locations. Such links are provided consistent with the stated purpose of this DoD Web site.");
    }
    else
    {
    window.alert("Still on our site.");
    window.location.reload();
    // var here = document.write(location.href);
    // document.write(location.href);
    // document.close();
    // window.location.replace("http:///enrdLinks.asp");
    // window.close();
    }
    }

    </script>
    You can see the items I've tried. I have also played with the anchor onclick event to see if the cancel would work inline.
    The //document.write(exiting); shows both the true and the false returns when uncommented, so the confirm is returning the correct option. The reload isn't reloading, as stated earlier. It goes to the new URL instead of staying on the page and reloading.

  4. #4
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: confirm() cancel and other js issue

    Try

    Virginia Department of Game and Inland Fisheries

    <script language="JavaScript">
    function exitsite()
    {
    var exiting = confirm("Click OK to leave the site. Click Cancel to stop.");

    if (exiting){
    alert("You are leaving a Fort Belvoir Army web site." + 'n' + "The appearance of hyperlinks does not constitute endorsement by the U.S. Army of this web site or the information, products or services contained therein. For other than authorized activities such as military exchanges and Morale, Welfare and Recreation sites, the U.S. Army does not exercise any editorial control over the information you may find at these locations. Such links are provided consistent with the stated purpose of this DoD Web site.");

    window.location = "http://www.dgif.state.va.us/";
    return;
    }
    else {
    alert("Still on our site.");

    }
    }

    </script>
    Jerry

  5. #5
    Star Lounger
    Join Date
    Feb 2003
    Location
    DC Metro, District Of Columbia, USA
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: confirm() cancel and other js issue

    Jerry, I have no issue with true - go to the link :: window.location = "http://www.dgif.state.va.us/"; return;... The issue is still : return false Still goes to the link, IE. cancel will not cancel the link event, I still get the cllicked link / page. The : else { alert("Still on our site."); window.location.reload(); } is not working, with or without the reload.

  6. #6
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: confirm() cancel and other js issue

    I know, but I have written code to negate the issue <img src=/S/evilgrin.gif border=0 alt=evilgrin width=15 height=15>

    By including the line window.location = "http://www.dgif.state.va.us/"; in the if clause and clearing the else it will work
    Jerry

  7. #7
    Star Lounger
    Join Date
    Feb 2003
    Location
    DC Metro, District Of Columbia, USA
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: confirm() cancel and other js issue

    I just tried it. Now, by still using target="_blank", the new window And the Belvoir page both go to the new link. Sigh. And, the cancel still does Not cancel, aaaarrrrrrggggggg (from Charles Brown). If Marvin the Robot would speak, but he's too depressed from my efforts to resolve this (grin).

  8. #8
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: confirm() cancel and other js issue

    Can I check?

    Have you copied and pasted my code as I have removed target="_blank" to stop that behaviour? <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

    Look at this line:

    Virginia Department of Game and Inland Fisheries

    The href is also set to # which, without the script code would not work but exitsite() has taken on that function.
    Jerry

  9. #9
    Star Lounger
    Join Date
    Feb 2003
    Location
    DC Metro, District Of Columbia, USA
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: confirm() cancel and other js issue

    BTW, tanx for the help. That said, here is the other boot, shoe, berkenstok, clog, flipflop, ...
    Oh! Was I supposed to read the First line of your response, he asks blushingly? Yes your code now works the cancel, not sure why, but.... Now, he asks with bated breath, how do I use this on the other fifteen links on the page, without the hardcoded -- window.location = "http://www.dgif.state.va.us/";-- in the function? AAAAAAAHHHHHHHH (¡¡¿Y am I such a pain?!!)

  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: confirm() cancel and other js issue

    Here is one approach, I think you will know where these snippets go:

    <code>Virginia Department of Game and Inland Fisheries</code>

    <code>function exitsite(destURL)</code>

    <code>window.location = destURL;</code>

    Note: the return false in the click handler is needed to prevent the page from submitting the link after the script runs. However, if the user has JavaScript disabled, the link will operate normally. If you do NOT want the link to work at all when the user has scripting disabled, then move the url into the parentheses where it currently says this.href.

  11. #11
    Star Lounger
    Join Date
    Feb 2003
    Location
    DC Metro, District Of Columbia, USA
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: confirm() cancel and other js issue

    You (plural) are the best! I can now keep my job for another xxxxx! I became a Woody lounger back when Mr. Chen was still around and you (plural) are still life and job savers. Between the two of your codes, I have an elegant exit routine for the page. I will deploy the code to the other pages (with links) on the site and make Big Army happy with our complying with the new regs. Woody, please give them some extra Woody bucks for their contributions to our US. Army. Tanx for the assist.

Posting Permissions

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