Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by duncanb7
at 2024-11-18 07:36:14
Point:500 Replies:3 POST_ID:828533USER_ID:11059
Topic:
JavaScript;;Hypertext Markup Language (HTML)
I would like to detect a click on body and report out what the click href link is clicking.
And I write the following example code with using function of onclick="processclick();" on body tag.
But when I click yahoo link or wiki link, the alert() is always report to the exisitng domain name
and path such as http://www.mywebsite.com/onclick.html
So whereever I click on the body area, it always report the same window.location.href whcih
is equal to http://www.mywebsite.com/onclick.html . I expect, it alert() me the yahoo or wiki path name
according to individual click
if possible, I can prevent my vistors going into
yahoo or wiki link by redirect into other link when they click the either link , this
is for example only.
How can I detect the yahoo or wiki click and its exact link path name by alert() before it load
or jump into www.yahoo.com or www.wiki.com web pages
I tried put onload="processclick();" in body tag, the result is keeping reporting the same
my website path such as http://www.mywebsite.com/onclick.html
How to capture the click event and its exact link path name
Please advise
Duncan
And I write the following example code with using function of onclick="processclick();" on body tag.
But when I click yahoo link or wiki link, the alert() is always report to the exisitng domain name
and path such as http://www.mywebsite.com/onclick.html
So whereever I click on the body area, it always report the same window.location.href whcih
is equal to http://www.mywebsite.com/onclick.html . I expect, it alert() me the yahoo or wiki path name
according to individual click
if possible, I can prevent my vistors going into
yahoo or wiki link by redirect into other link when they click the either link , this
is for example only.
How can I detect the yahoo or wiki click and its exact link path name by alert() before it load
or jump into www.yahoo.com or www.wiki.com web pages
I tried put onload="processclick();" in body tag, the result is keeping reporting the same
my website path such as http://www.mywebsite.com/onclick.html
How to capture the click event and its exact link path name
Please advise
Duncan
///http://www.mywebsite.com/onclick.html<html><head><script type="text/javascript">function processclick(){alert(window.location.href);}</script></head><body onclick="processclick();"><a href="http://www.yahoo.com">Yahoo Website</a><a href="http://www.wiki.com">Wiki Website</a></body></html> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:
Author: duncanb7 replied at 2024-11-18 08:13:34
html>
<head>
<script type="text/javascript">
function processclick()
{
alert(event.srcElement.href);
event.srcElement.href="http://www.otherwebsite.com";
}
</script>
</head>
<body onclick="processclick();">
<a href="http://www.yahoo.com" >Yahoo Website</a>
<a href="http://www.wiki.com" >Wiki Website</a>
</body>
</html>
<head>
<script type="text/javascript">
function processclick()
{
alert(event.srcElement.href);
event.srcElement.href="http://www.otherwebsite.com";
}
</script>
</head>
<body onclick="processclick();">
<a href="http://www.yahoo.com" >Yahoo Website</a>
<a href="http://www.wiki.com" >Wiki Website</a>
</body>
</html>
Accepted Solution
Author: duncanb7 replied at 2024-11-18 08:12:10
html>
<head>
<script type="text/javascript">
function processclick()
{
alert(event.srcElement.href);
event.srcElement.href="http://www.otherwebsite.com";
}
</script>
</head>
<body onclick="processclick();">
<a href="http://www.yahoo.com" >Yahoo Website</a>
<a href="http://www.wiki.com" >Wiki Website</a>
</body>
</html>
<head>
<script type="text/javascript">
function processclick()
{
alert(event.srcElement.href);
event.srcElement.href="http://www.otherwebsite.com";
}
</script>
</head>
<body onclick="processclick();">
<a href="http://www.yahoo.com" >Yahoo Website</a>
<a href="http://www.wiki.com" >Wiki Website</a>
</body>
</html>
Assisted Solution
Expert: nap0leon replied at 2024-11-18 07:51:07
500 points EXCELLENT
If you don't mind moving the onlick into each <a> you can do this:
<html><head><script type="text/javascript">function processclick(obj){alert(obj.href);}</script></head><body><a href="http://www.yahoo.com" onclick="processclick(this);">Yahoo Website</a><a href="http://www.wiki.com" onclick="processclick(this);">Wiki Website</a></body></html> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15: