473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Can a Hyperlink call a Javascript confirm prompt?

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.
Mar 17 '06 #1
17 3825
Chris Ianson wrote:
Hi, I have this JavaScript, which I only want to occur
Probably you mean "execute".
if a user clicks on a hyperlink hotspot in a large image:

<script type="text/javascript">
<!-- ^^^^
Nonsense.
var answer = confirm ("This link is not available, click OK to load a
similar link, or Cancel to not.")


Utter nonsense. What about users without client-side script support? If you
discover that a link does not work, remove it (the link, not necessarily
its content). If you want to work around broken links until you have time
to fix them (one way or the other), do that server-side, not (only)
client-side.

And stop crossposting to alt.* and the Big Eight (incl. comp.*).
PointedEars
Mar 18 '06 #2
Any ideas guys?

"Chris Ianson" <no***@hotmail.com> wrote in message
news:v2*****************@text.news.blueyonder.co.u k...
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.

Mar 18 '06 #3

"Chris Ianson" <no***@hotmail.com> wrote in message
news:v2*****************@text.news.blueyonder.co.u k...
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?')"

Mar 18 '06 #4
"Vic Sowers" <Mail@Vic_NOSPAM_Sowers.com> wrote in message
news:WM****************@tornado.texas.rr.com...
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. :)
Mar 18 '06 #5
Chris Ianson wrote:
"Vic Sowers" <Mail@Vic_NOSPAM_Sowers.com> wrote in message
news:WM****************@tornado.texas.rr.com...
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
Mar 18 '06 #6
Thank Jonathan, that was very helpful of you.
Mar 18 '06 #7
JRS: In article <14****************@PointedEars.de>, dated Sat, 18 Mar
2006 06:22:19 remote, seen in news:comp.lang.javascript, Thomas
'PointedEars' Lahn <Po*********@web.de> 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.
Mar 19 '06 #8
"Lee" <RE**************@cox.net> wrote in message
news:dv*********@drn.newsguy.com...
Why not just set the HREF of these AREA tags to the URL that you're
going to send them to, and simply cancel the click if they choose
cancel:

<area href="http://www.yahoo.com"
onclick="return confirm('this link is ..., or cancel')">


Thanks for the very helpful reply Lee.
Mar 19 '06 #9
"Jonathan N. Little" <lw*****@centralva.net> wrote in message
news:44**********************@news.centralva.net.. .
<!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?
Mar 19 '06 #10
Chris Ianson wrote:
"Jonathan N. Little" <lw*****@centralva.net> wrote in message
news:44**********************@news.centralva.net.. .
<!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
Mar 19 '06 #11
"Jonathan N. Little" <lw*****@centralva.net> wrote in message
news:44**********************@news.centralva.net.. .
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.
Mar 20 '06 #12
PS: Is it possible to insert a line break in the text that appears in the
prompt confirmation box?
Mar 20 '06 #13
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/
Mar 20 '06 #14
"Chris Ianson" <no***@hotmail.com> 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 - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Mar 20 '06 #15
"Randy Webb" <Hi************@aol.com> wrote in message
news:B4********************@comcast.com...
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.
Mar 20 '06 #16
Chris Ianson said on 20/03/2006 12:00 PM AEST:
"Randy Webb" <Hi************@aol.com> wrote in message
news:B4********************@comcast.com...
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
Mar 20 '06 #17
Chris Ianson said the following on 3/19/2006 9:00 PM:
"Randy Webb" <Hi************@aol.com> wrote in message
news:B4********************@comcast.com...
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/
Mar 20 '06 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: cheezebeetle | last post by:
ok, so I am having problems passing in an ASPX function into the Javascript in the codebehind page. I am simply using a confirm call which when they press "OK" they call this ASPX function, when...
4
by: Don Grover | last post by:
I hope some one can help, I have a html table that is created with asp that has a row of repeated buttons down the side. these call a page passing a query string with invoice number. I need to...
2
by: neoconwannabe | last post by:
Hi, I have an html form with a number of checkboxes that can be checked to delete items. I want to have a javascript alert prompt box to pop up to confirm the delete. I am building my site with...
6
by: Chris Markle | last post by:
Javascript confirm call outputs a dialogue box that writes out a message and gives two choices: OK and Cancel. Can those buttons be relabelled say to "Yes" and "No"?
1
by: Pat | last post by:
All, What I want to do: ******************* Click on a hyperlink in the last column in a datagrid, have it grab a value in the fourth column in the same row and send it to the codehind into a...
6
by: sck10 | last post by:
Hello, Can you control the window attributes (toolbar, scrollbars, left and right exc.) when using the hyperlink control as you would when using javascript? For examle, I am using the...
9
by: RA | last post by:
While dynamically creating the table; I am adding a hyperlink as a TableCell where text is "Delete". Initially it is disabled and if a checkbox is selected from a table then it gets enabled. Even...
3
by: J.P. Cummins | last post by:
In my ASP.NET application, I wish to have a page for administrators to edit items in a list. Preferably, I would like to use the javascript prompt for the 'rename' function, and a javascript alert...
19
by: Joe | last post by:
I have an aspx page (referred to here as page_1) with a datagrid whose first column contains hyperlinks. When a user clicks one of these hyperlinks, he will navigate to another aspx page (referred...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.