modifying anchor elements

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • v

    modifying anchor elements

    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
  • Dietmar Meier

    #2
    Re: modifying anchor elements

    v wrote:
    [color=blue]
    > 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?[/color]

    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.defaultS tatus;
    }
    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

    Comment

    • v

      #3
      Re: modifying anchor elements


      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"
      <usereplytoinst ead@innoline-systemtechnik.d e> wrote:
      [color=blue]
      >v wrote:
      >[color=green]
      >> 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?[/color]
      >
      >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.defaultS tatus;
      >}
      >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.onloa d = initLinks;
      >
      >ciao, dhgm[/color]

      Comment

      • Fred Oz

        #4
        Re: modifying anchor elements

        v wrote:
        [color=blue]
        > thanx :-)
        > hmm.. but maybe you're right there.
        > Would it be possible to do the same with span, p or some other
        > elements.?[/color]

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

        [...][color=blue][color=green][color=darkred]
        >>>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?[/color][/color][/color]

        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="al ert(this.innerT ext);">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

        Comment

        Working...