SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict djh's Avatar
    Join Date
    Apr 2000
    Location
    Long Beach, CA
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Confirm alert boxes

    Does someone know what the javascript is to create confirm boxes for a link?

    Only tricky this is that there is more than one link on the page that should use the same function - and each link is to a different page.

    So the function should read the variable link and proceed..

    I'm a javascript newbie so I don't even know this...

    can you pass a variable within parenthesis of a function call, e.g. callconfirm(x)?

  2. #2
    SitePoint Enthusiast RogueJedi's Avatar
    Join Date
    Oct 2001
    Location
    Texas
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    PHP Code:
    <script language="JavaScript" type="text/javascript">
        function 
    confirmLink(URL) {
            if(
    confirm("Are you sure you want to follow this link?")) {
                
    alert(URL);
                
    window.location.href URL;
            } else {
                
    alert("You chose to follow the link.");
            }
        }
    </script>

    <p><a href="javascript:confirmLink('http://www.dell.com')">Click here now!</a></p> 
    Just pass the complete URL to the function.
    Rob Nolan
    Do or do not, there is no try.

  3. #3
    SitePoint Addict djh's Avatar
    Join Date
    Apr 2000
    Location
    Long Beach, CA
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    fantastic. so you can do it that way.

    one twist....

    can i open the link in a new window or call a function like below? Right now I'm doing:
    Code:
    <a href="javascript:openWin('/URLhere','winName','resizable=yes,scrollbars=yes,width=700,height=500')"
    How do I incorporate that into your function?

    Thanks Rogue!

  4. #4
    SitePoint Member
    Join Date
    Feb 2002
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    confirm alert boxes

    Hello djh

    I hope this helps:

    <html>
    <head>
    <title>New window</title>
    <script language="JavaScript">
    <!----
    function Openwin(url)
    {
    if(confirm('Are sure you want to follow this link?'))
    {
    alert('You chose to follow this link');
    windowlink=window.open(url,'windowname','resizable=yes,scrollbars=yes,width=700,height=500');
    }
    else
    {
    alert('You chose not to follow this link');
    }
    }
    //-------->
    </script>
    </head>
    <body>
    <div align="center">
    <a href="javascript:Openwin('http://www.dell.com')">Clike here</a>
    </div>
    </body>
    </html>

    Kindest Regards

    Alex


Bookmarks

Posting Permissions

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