Can a Hyperlink call a Javascript confirm prompt?

C

Chris Ianson

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.
 
V

Vic Sowers

Chris Ianson said:
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?')"
 
C

Chris Ianson

Vic Sowers said:
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. :)
 
J

Jonathan N. Little

Chris said:
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>
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Sat, 18 Mar
2006 06:22:19 remote, seen in Thomas
'PointedEars' Lahn said:
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.
 
C

Chris Ianson

<!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?
 
J

Jonathan N. Little

Chris said:
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....
 
C

Chris Ianson

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.
 
C

Chris Ianson

PS: Is it possible to insert a line break in the text that appears in the
prompt confirmation box?
 
L

Lasse Reichstein Nielsen

Chris Ianson said:
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
 
R

Randy Webb

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
 
C

Chris Ianson

Randy Webb said:
Chris Ianson said the following on 3/19/2006 8:05 PM:

\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.
 
R

RobG

Chris Ianson said on 20/03/2006 12:00 PM AEST:
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.
 
R

Randy Webb

Chris Ianson said the following on 3/19/2006 9:00 PM:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top