35 users online (2 members and 33 guests)  


  Results 1 to 4 of 4

Related

  1. supress browser alert    Forum: Javascript Forum
    Replies: 1
  2. How many characters in a confirm/alert box?    Forum: Javascript Forum
    Replies: 1
  3. alert if not using IE    Forum: HTML Forum
    Replies: 1
  4. farewell alert    Forum: Javascript Forum
    Replies: 2
  5. javascript alert box    Forum: Javascript Forum
    Replies: 7
  1. #1
    rtravis's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2008
    Posts
    2

    Is it possible to add a link in an alert box?

    Hi folks,
    I just joined the forum, and I'm hoping someone here can help me.

    I have created a javascript alert box for my company's website that pops up when a visitor clicks on someone's email address. Basically it gives a disclaimer saying that emailing the person does not set up a business relationship. Clicking the "ok" button lets them continue and compose the email. Clicking "Cancel" closes the box and nothing happens. (of course, they can just copy and paste the email address, but at least they've been warned!)

    What I'm wondering is if there is a way to include a link in the text of the alert box. I want to link to the Terms and Conditions page on our website from the message.

    I tried inserting the <a href></a> tags but it doesn't work. It only disables the alert box..... I'm new to JavaScript, so I know I'm probably just doing something wrong.... But I swear I've seen this sort of thing done before.

    I've searched all over a bunch of websites and a couple of books, but can't find an answer. And now my head just hurts.... Any help would be very much appreciated!

    Here's the code I'm using (fyi - I scooped it from the source code on another site, and altered the text, obviously)

    <head>
    <script type="text/javascript">
    function emailWarning()
    {
    var messageBody="The text is being finalized. Here's where it will go\n\n";
    messageBody = messageBody + "And the text with the link will go here.\n\n";
    return window.confirm(messageBody);
    }
    </script>
    </head>

    and at the bottom of the page, just before the </body> tag:

    <script type="text/javascript">
    for(i=0;i<document.links.length;i++)
    {
    if(document.links[i].protocol == "mailto:")
    {
    document.links[i].onclick = function() {return emailWarning();
    }
    }
    }
    </script>

  2. #2
    rangana's Avatar
    Moderator/Allstar

    Status
    Offline
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    317

    Re: Is it possible to add a link in an alert box?

    If you want to include messages and links, don't use JS alert, instead use window.open
    This link might help you:
    http://www.quirksmode.org/js/popup.html
    Get back if you're stumped

  3. #3
    rtravis's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2008
    Posts
    2

    Re: Is it possible to add a link in an alert box?

    Thanks rangana! Looks like that might do the trick.
    I had considered a pop-up window using TARGET="_blank", but wasn't sure if I could make it a small fixed-size window.
    I give this a try and let you know how it goes!

  4. #4
    rangana's Avatar
    Moderator/Allstar

    Status
    Offline
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    317

    Re: Is it possible to add a link in an alert box?

    No problem...do get back if you're still stumped



Tags for this Thread