Can a Hyperlink call a Javascript confirm prompt?

Discussion in 'HTML' started by Chris Ianson, Mar 17, 2006.

  1. Chris Ianson

    Chris Ianson Guest

    Hi, I have this JavaScript, which I only want to occur if a user clicks on a
    hyperlink hotspot in a large image:

    <script type="text/javascript">
    <!--
    var answer = confirm ("This link is not available, click OK to load a
    similar link, or Cancel to not.")
    if (!answer)
    window.location="http://www.yahoo.com/"
    // -->
    </script>

    To make matters more challenging, there are about 10 hotspots in the image,
    and I want them each to have a different value for window.location. I.e. if
    the user clicks OK in each hotspot, each one will redirect them to a
    different site.

    Any clever-clogs out there who can help out? :)

    Thanks in advance.
    Chris Ianson, Mar 17, 2006
    #1
    1. Advertising

  2. Chris Ianson

    Chris Ianson Guest

    Any ideas guys?

    "Chris Ianson" <> wrote in message
    news:v2HSf.37635$...
    > Hi, I have this JavaScript, which I only want to occur if a user clicks on
    > a hyperlink hotspot in a large image:
    >
    > <script type="text/javascript">
    > <!--
    > var answer = confirm ("This link is not available, click OK to load a
    > similar link, or Cancel to not.")
    > if (!answer)
    > window.location="http://www.yahoo.com/"
    > // -->
    > </script>
    >
    > To make matters more challenging, there are about 10 hotspots in the
    > image, and I want them each to have a different value for window.location.
    > I.e. if the user clicks OK in each hotspot, each one will redirect them to
    > a different site.
    >
    > Any clever-clogs out there who can help out? :)
    >
    > Thanks in advance.
    >
    Chris Ianson, Mar 18, 2006
    #2
    1. Advertising

  3. Chris Ianson

    Vic Sowers Guest

    "Chris Ianson" <> wrote in message
    news:v2HSf.37635$...
    > Hi, I have this JavaScript, which I only want to occur if a user clicks on
    > a hyperlink hotspot in a large image:
    >
    > <script type="text/javascript">
    > <!--
    > var answer = confirm ("This link is not available, click OK to load a
    > similar link, or Cancel to not.")
    > if (!answer)
    > window.location="http://www.yahoo.com/"
    > // -->
    > </script>
    >
    > To make matters more challenging, there are about 10 hotspots in the
    > image, and I want them each to have a different value for window.location.
    > I.e. if the user clicks OK in each hotspot, each one will redirect them to
    > a different site.
    >
    > Any clever-clogs out there who can help out? :)
    >
    > Thanks in advance.
    >


    Try setting the href="http://www.yahoo.com/" and onClick="return confirm("Do
    you really want Yahoo?')"
    Vic Sowers, Mar 18, 2006
    #3
  4. Chris Ianson

    Chris Ianson Guest

    "Vic Sowers" <Mail@Vic_NOSPAM_Sowers.com> wrote in message
    news:WMSSf.4850$...
    > Try setting the href="http://www.yahoo.com/" and onClick="return
    > confirm("Do you really want Yahoo?')"


    Thanks Vic but I'm quite new to this. Could you kindly show me the exact
    code to 'copy and paste'? Then I can understand it for next time. Not sure
    about onClick etc. Thanks again. :)
    Chris Ianson, Mar 18, 2006
    #4
  5. Chris Ianson wrote:

    > "Vic Sowers" <Mail@Vic_NOSPAM_Sowers.com> wrote in message
    > news:WMSSf.4850$...
    >
    >>Try setting the href="http://www.yahoo.com/" and onClick="return
    >>confirm("Do you really want Yahoo?')"

    >
    >
    > Thanks Vic but I'm quite new to this. Could you kindly show me the exact
    > code to 'copy and paste'? Then I can understand it for next time. Not sure
    > about onClick etc. Thanks again. :)
    >
    >


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Test Confirm Box</title>
    </head>
    <body>
    <h1>Test Confirm</h1>
    <p>
    To test how code a confirm on click,
    click <a href="http://www.yahoo.com/"
    onclick="return confirm('Do you really want Yahoo?')">
    Go To Yahoo</a>
    </p>
    </body>
    </html>



    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    Jonathan N. Little, Mar 18, 2006
    #5
  6. Chris Ianson

    Chris Ianson Guest

    Thank Jonathan, that was very helpful of you.
    Chris Ianson, Mar 18, 2006
    #6
  7. JRS: In article <>, dated Sat, 18 Mar
    2006 06:22:19 remote, seen in news:comp.lang.javascript, Thomas
    'PointedEars' Lahn <> posted :
    >
    >And stop crossposting to alt.* and the Big Eight (incl. comp.*).
    >


    There's nothing wring with that by Big-8 rules.

    German hierarchy rules are irrelevant here.

    Please stop being a Kontrol Freak, and engage a good psychiatrist.

    As you must realise, I don't find German quick to read. Are users of
    de.c.l.j as disgusted with your arrogance as so many of us here are
    (ISTM from what they post that they may well be? Perhaps MH would
    venture an unprejudiced opinion.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME ©
    Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
    Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
    No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
    Dr John Stockton, Mar 19, 2006
    #7
  8. Chris Ianson

    Chris Ianson Guest

    "Jonathan N. Little" <> wrote in message
    news:441c1496$0$3708$...

    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    > "http://www.w3.org/TR/html4/strict.dtd">
    > <html>
    > <head>
    > <title>Test Confirm Box</title>
    > </head>
    > <body>
    > <h1>Test Confirm</h1>
    > <p>
    > To test how code a confirm on click,
    > click <a href="http://www.yahoo.com/"
    > onclick="return confirm('Do you really want Yahoo?')">
    > Go To Yahoo</a>
    > </p>
    > </body>
    > </html>


    Hmm, any idea why some popup blockers such as Google's seem to block the
    link from opening when OK is clicked?
    Chris Ianson, Mar 19, 2006
    #8
  9. Chris Ianson wrote:
    > "Jonathan N. Little" <> wrote in message
    > news:441c1496$0$3708$...
    >
    >> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    >> "http://www.w3.org/TR/html4/strict.dtd">
    >> <html>
    >> <head>
    >> <title>Test Confirm Box</title>
    >> </head>
    >> <body>
    >> <h1>Test Confirm</h1>
    >> <p>
    >> To test how code a confirm on click,
    >> click <a href="http://www.yahoo.com/"
    >> onclick="return confirm('Do you really want Yahoo?')">
    >> Go To Yahoo</a>
    >> </p>
    >> </body>
    >> </html>

    >
    > Hmm, any idea why some popup blockers such as Google's seem to block the
    > link from opening when OK is clicked?
    >
    >


    If you add a 'target' attribute to your link on a page that is NOT
    contained in frames it will open a new window, i.e., a popup window....

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    Jonathan N. Little, Mar 19, 2006
    #9
  10. Chris Ianson

    Chris Ianson Guest

    "Jonathan N. Little" <> wrote in message
    news:441de80c$0$3701$...

    > If you add a 'target' attribute to your link on a page that is NOT
    > contained in frames it will open a new window, i.e., a popup window....


    Yep that I know, but there are many links on this page and none of them are
    blocked by Google's popup blocker, except the one with the code you gave for
    the confirmation prompt. Bizarre.
    Chris Ianson, Mar 19, 2006
    #10
  11. Chris Ianson

    Chris Ianson Guest

    PS: Is it possible to insert a line break in the text that appears in the
    prompt confirmation box?
    Chris Ianson, Mar 20, 2006
    #11
  12. "Chris Ianson" <> writes:

    > Yep that I know, but there are many links on this page and none of them are
    > blocked by Google's popup blocker, except the one with the code you gave for
    > the confirmation prompt. Bizarre.


    Probably an attempt at detecting which popups follow from user interaction
    and which doesn't. Since the last click made with the mouse before the popup
    attempts to open was to the alert window, and not the page itself, it counts
    as an unrequested popup.
    It's just a guess, but it could explain the observed behavior.

    /L
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Mar 20, 2006
    #12
  13. Chris Ianson

    Randy Webb Guest

    Chris Ianson said the following on 3/19/2006 8:05 PM:
    > PS: Is it possible to insert a line break in the text that appears in the
    > prompt confirmation box?


    \n is a new line in the confirmation.

    confirm('This is\n text with a \n linebreak')

    Same thing with an alert

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, Mar 20, 2006
    #13
  14. Chris Ianson

    Chris Ianson Guest

    "Randy Webb" <> wrote in message
    news:...
    > Chris Ianson said the following on 3/19/2006 8:05 PM:
    >> PS: Is it possible to insert a line break in the text that appears in the
    >> prompt confirmation box?

    >
    > \n is a new line in the confirmation.
    >
    > confirm('This is\n text with a \n linebreak')
    >
    > Same thing with an alert


    Thanks, I had tried that but it just printed '/n' in the box! Works now
    though, I must have done something wrong.
    Chris Ianson, Mar 20, 2006
    #14
  15. Chris Ianson

    RobG Guest

    Chris Ianson said on 20/03/2006 12:00 PM AEST:
    > "Randy Webb" <> wrote in message
    > news:...
    >
    >>Chris Ianson said the following on 3/19/2006 8:05 PM:
    >>
    >>>PS: Is it possible to insert a line break in the text that appears in the
    >>>prompt confirmation box?

    >>
    >>\n is a new line in the confirmation.
    >>
    >>confirm('This is\n text with a \n linebreak')
    >>
    >>Same thing with an alert

    >
    >
    > Thanks, I had tried that but it just printed '/n' in the box! Works now

    -----------------------------------------------^^^

    > though, I must have done something wrong.


    Yes, newline is \n not /n.


    --
    Rob
    RobG, Mar 20, 2006
    #15
  16. Chris Ianson

    Randy Webb Guest

    Chris Ianson said the following on 3/19/2006 9:00 PM:
    > "Randy Webb" <> wrote in message
    > news:...
    >> Chris Ianson said the following on 3/19/2006 8:05 PM:
    >>> PS: Is it possible to insert a line break in the text that appears in the
    >>> prompt confirmation box?

    >> \n is a new line in the confirmation.
    >>
    >> confirm('This is\n text with a \n linebreak')
    >>
    >> Same thing with an alert

    >
    > Thanks, I had tried that but it just printed '/n' in the box! Works now
    > though, I must have done something wrong.


    You used /n instead of \n, note the different slash.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, Mar 20, 2006
    #16
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gaurav kashyap
    Replies:
    2
    Views:
    591
    gaurav kashyap
    Oct 30, 2008
  2. gaurav kashyap
    Replies:
    3
    Views:
    654
    gaurav kashyap
    Oct 31, 2008
  3. Jeremy Redmond
    Replies:
    2
    Views:
    93
    Jeremy Redmond
    Nov 6, 2004
  4. Hans
    Replies:
    2
    Views:
    301
  5. Chris Ianson
    Replies:
    17
    Views:
    308
    Randy Webb
    Mar 20, 2006
Loading...

Share This Page