473,320 Members | 1,744 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,320 software developers and data experts.

modifying anchor elements

v
Hi guys,
Is it possible to use a simple code to modify all the anchor elements
on a web page to trigger a function

eg to display the link innnertext on the window status upon mouseover?

....Or do I have to laboriously do it for every single link?

thanx,
v
Jul 23 '05 #1
3 1402
v wrote:
Is it possible to use a simple code to modify all the anchor elements
on a web page to trigger a function

eg to display the link innnertext on the window status upon mouseover?


The status bar content is an important information for most users, so
you are not supposed to change it's functionality. If you want to do
so anyway, you can use something like this:

function linkMOut() {
window.status = window.defaultStatus;
}
function linkMOver() {
var s;
if (this && (s = this.text || this.innerText)) {
window.status = s
return true;
}
else return false;
}
function initLinks() {
var i, j, k, oDoc = arguments[0] || window.document;
if (oDoc && (k = oDoc.links) && (j = k.length))
for (i=0; i<j; i++) {
k[i].onmouseover = linkMOver;
k[i].onmouseout = linkMOut;
}
if ((k = oDoc.layers) && (j = k.length))
for (i=0; i<j; i++)
if (k[i].document)
initLinks(k[i].document);
}
window.onload = initLinks;

ciao, dhgm
Jul 23 '05 #2
v

thanx :-)
hmm.. but maybe you're right there.
Would it be possible to do the same with span, p or some other
elements.?

v

On Mon, 24 Jan 2005 15:16:27 +0100, "Dietmar Meier"
<us***************@innoline-systemtechnik.de> wrote:
v wrote:
Is it possible to use a simple code to modify all the anchor elements
on a web page to trigger a function

eg to display the link innnertext on the window status upon mouseover?


The status bar content is an important information for most users, so
you are not supposed to change it's functionality. If you want to do
so anyway, you can use something like this:

function linkMOut() {
window.status = window.defaultStatus;
}
function linkMOver() {
var s;
if (this && (s = this.text || this.innerText)) {
window.status = s
return true;
}
else return false;
}
function initLinks() {
var i, j, k, oDoc = arguments[0] || window.document;
if (oDoc && (k = oDoc.links) && (j = k.length))
for (i=0; i<j; i++) {
k[i].onmouseover = linkMOver;
k[i].onmouseout = linkMOut;
}
if ((k = oDoc.layers) && (j = k.length))
for (i=0; i<j; i++)
if (k[i].document)
initLinks(k[i].document);
}
window.onload = initLinks;

ciao, dhgm


Jul 23 '05 #3
v wrote:
thanx :-)
hmm.. but maybe you're right there.
Would it be possible to do the same with span, p or some other
elements.?


Please don't top post. In answer to the question, yes, but
there are better ways of achieving the same result.

[...]
Is it possible to use a simple code to modify all the anchor elements
on a web page to trigger a function

eg to display the link innnertext on the window status upon mouseover?


innerText is IE only and therefore will not work for an
increasing number of your visitors.

Most browsers display information in the status bar that, for
anchors, says where the link is going to. Some will also advise
if the link will open in a new window or tab too.

What is the point of showing the innnerText? Isn't it already
displayed on the screen as part of the document?

<a href="http://www.apple.com"
onmouseover="alert(this.innerText);">Here is a link</a>

Will display an alert with "Here is a link" for IE and
"undefined" for other browsers. A more cross-browser method is
available using DOM methods, but it seems pointless.

If you want a tool-tip, use the title attribute on your links:

<a href="http://www.apple.com"
title="Here is a link to Apple">Apple</a>

No JavaScript required at all. Otherwise, the method
described by Dietmar for attaching events is, in general, fine.

--
Fred
Jul 23 '05 #4

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

Similar topics

4
by: deko | last post by:
I use named anchors to take users to specific parts of a long page. But I want to add some processing and do some things with my nav bar when users go to certain sections delineated by named...
6
by: Daniele Baroncelli | last post by:
Hi guys, I would like to change the text in an anchor. es. from <a id="idanchor">oldtext</a> to
5
by: elsenraat_76 | last post by:
Hello! I was wondering if someone could help me out with a problem I'm having? I'm trying to input a javascript value into an anchor tag (from a function), but don't have an event to call the...
0
by: Dave Elliott | last post by:
After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is after the newly added row without getting bizarre results. I have added the...
10
by: elibol | last post by:
Hi, Is there an event that fires when the back or forward button on a browser is pressed? I need an event to fire when someone clicks the back or forward button after an anchor has been set. ...
16
by: Frances | last post by:
<a href="#1"> <a name="#1"> this link is not working in FF (works fine in IE..) would appreciate thoughts/suggestions.. thank you.. Frances
8
by: maya | last post by:
I have some links.. http://www.francesdelrio.com/linksCSS.html want it so when you hover over link ENTIRE DIV gets gray bg color (not just text (like link Three is now on this page..) but...
3
by: bloc | last post by:
I am programming an interactive CV using xml, xslt and java script. The page consists of a header which contains links to various 'sections' on the xml cv, a left and right menu, and a central...
11
by: GaryB | last post by:
Hi Guys, I've been battling with this one for hours - I hope that you can help me! My code modifies the <aon a page, from a standard document link into a link with a tailored onclick event. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.