468,101 Members | 1,339 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,101 developers. It's quick & easy.

Anchors!

Hi,

A document has many Anchors.
I want to take a particular action only if some particular anchors
are clicked.
I mean if some anchors are clicked, i want an alert box to pop up
with ok and cancel. and if ok is clicked i have to view that link, if
cancel, then it should not open that link.
How to do this?

Jul 23 '05 #1
2 1724

"learner" <v_********@yahoo.com> wrote in message
news:cg********@odah37.prod.google.com...
Hi,

A document has many Anchors.
I want to take a particular action only if some particular anchors
are clicked.
I mean if some anchors are clicked, i want an alert box to pop up
with ok and cancel. and if ok is clicked i have to view that link, if
cancel, then it should not open that link.
How to do this?


HTML doesn't pop up alert boxes. That's a Javascript question, for a
Javascript newsgroup.

Jul 23 '05 #2
In article <cg********@odah37.prod.google.com>,
"learner" <v_********@yahoo.com> wrote:
A document has many Anchors.
I want to take a particular action only if some particular anchors
are clicked.
I mean if some anchors are clicked, i want an alert box to pop up
with ok and cancel. and if ok is clicked i have to view that link, if
cancel, then it should not open that link.
How to do this?

A JavaScript-only solution:
<a href="http://www.google.com/"
onclick="return confirm('Are you sure
you want to follow this link?');">

This will only work for people with JavaScript enabled.
A non-JavaScript solution is to refer to a server side script that
checks if the URl needs intervention (characteristics of the URL, a
database or some other argument [1]) and will either cause an immediate
redirect to that URL or pause and ask for the visitor's confirmation.

Something like:
<a href="redirect.php?url=www.google.com">

[1] Passing more arguments, to tell the script to intervene for this
particular URL:
<a href="redirect.php?stop=true&amp;url=www.google.co m">
A crossbreed solution of these two suggestions is also possible by
having the JavaScript interrupt the browser from following the link,
evaluating if the link needs a confirmation, ask for it and redirect to
the URL that gets extracted from the href attribute.
Another solution, in case you are looking for some kind of disclaimer
system, is to state upfront that links that are marked a certain way are
'special', 'adult', or whatever, and are to be treated with user
discretion. Then mark those links, for instance by adding an icon or
textual comment to them.

--
Kris
<kr*******@xs4all.netherlands> (nl)
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Ben Wilson | last post: by
2 posts views Thread by mlv2312 | last post: by
1 post views Thread by mlv2312 | last post: by
21 posts views Thread by adrian suri | last post: by
12 posts views Thread by Rich | last post: by
3 posts views Thread by windandwaves | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.