title = status ? - part 2

Discussion in 'Javascript' started by NielsM, Feb 28, 2007.

  1. NielsM

    NielsM Guest

    Hello All,

    Found a bit of Javascript on this forum that shows the title-text of a
    link in the statusbar, so you don't have to type
    onmouseover="window.status='bla di bla'" in every link.

    http://groups.google.nl/group/comp....read/thread/16906e69836826c3/4922a5c1a40fd2a1

    But it does not show the title when the link (<a href=""..>text</a>)
    is in a DIV tag.
    Can someone help me so all links on my page have a statusbar text on
    mouse over no matter how deep they are nested.

    Some example code:
    <html>
    <head>
    <title>Test javascript title</title>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1">
    <script>
    function setMEvents() {
    var oDocBodyNodes = document.body.childNodes;
    for (var i = 0; i < oDocBodyNodes.length; i++) {
    if (oDocBodyNodes.nodeType == 1 && typeof
    oDocBodyNodes.title != 'undefined') {
    oDocBodyNodes.onmouseover = function() { window.status
    = this.title; return true; }
    oDocBodyNodes.onmouseout = function() { window.status =
    ''; return true; }
    }
    }
    }
    </script>
    </head>
    <body onload="setMEvents()">
    <div id="test">this link is inside a DIV tag <a href="#" title="does
    not work">and therefore does not work</a></div>
    <a href="#" title="This works">This is a normal link which shows the
    title in the statusbar on mouse over</a>
    <div id="level0"> <a href="#" title="link in div">link level 0 - link
    in div</a><br>
    <div id="level1"> <a href="#" title="link in div in div">link level
    1 - link in div in div</a></div>
    </div>
    </body>
    </html>

    Thanks,
    Niels

    PS: This only works in Internet Explorer since FireFox does not
    support the statusbar text option.
    PS 2: I do not want to go into a discussion about the use (or mis-use)
    of the statusbar and it's intentional purpose. It all about optimizing
    my code to get a smaller page size
     
    NielsM, Feb 28, 2007
    #1
    1. Advertising

  2. NielsM

    Tom Cole Guest

    On Feb 28, 11:48 am, "NielsM" <> wrote:
    > Hello All,
    >
    > Found a bit of Javascript on this forum that shows the title-text of a
    > link in the statusbar, so you don't have to type
    > onmouseover="window.status='bla di bla'" in every link.
    >
    > http://groups.google.nl/group/comp.lang.javascript/browse_thread/thre...
    >
    > But it does not show the title when the link (<a href=""..>text</a>)
    > is in a DIV tag.
    > Can someone help me so all links on my page have a statusbar text on
    > mouse over no matter how deep they are nested.
    >
    > Some example code:
    > <html>
    > <head>
    > <title>Test javascript title</title>
    > <meta http-equiv="Content-Type" content="text/html;
    > charset=iso-8859-1">
    > <script>
    > function setMEvents() {
    > var oDocBodyNodes = document.body.childNodes;
    > for (var i = 0; i < oDocBodyNodes.length; i++) {
    > if (oDocBodyNodes.nodeType == 1 && typeof
    > oDocBodyNodes.title != 'undefined') {
    > oDocBodyNodes.onmouseover = function() { window.status
    > = this.title; return true; }
    > oDocBodyNodes.onmouseout = function() { window.status =
    > ''; return true; }
    > }
    > }}
    >
    > </script>
    > </head>
    > <body onload="setMEvents()">
    > <div id="test">this link is inside a DIV tag <a href="#" title="does
    > not work">and therefore does not work</a></div>
    > <a href="#" title="This works">This is a normal link which shows the
    > title in the statusbar on mouse over</a>
    > <div id="level0"> <a href="#" title="link in div">link level 0 - link
    > in div</a><br>
    > <div id="level1"> <a href="#" title="link in div in div">link level
    > 1 - link in div in div</a></div>
    > </div>
    > </body>
    > </html>
    >
    > Thanks,
    > Niels
    >
    > PS: This only works in Internet Explorer since FireFox does not
    > support the statusbar text option.
    > PS 2: I do not want to go into a discussion about the use (or mis-use)
    > of the statusbar and it's intentional purpose. It all about optimizing
    > my code to get a smaller page size


    This seemed pretty easy:

    function setMEvents() {
    for (var i = 0; i < document.getElementsByTagName("a").length; i++) {
    var node = document.getElementsByTagName("a");
    if (node.title) {
    node.onmouseover = function () { window.status = this.title; return
    true; }
    node.onmouseout = function () { window.status = ''; return true; }
    }
    }
    }
     
    Tom Cole, Feb 28, 2007
    #2
    1. Advertising

  3. NielsM

    NielsM Guest

    Wow it works, THANKS a lot !!

    This may seemed easy for you... I have no programming skills and
    fooled around with the 'ChildNodes' to get it working with no results
    of course ;-) Looks like the getElementsByTagName does the trick.

    Thanks again Tom.
     
    NielsM, Feb 28, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Klemt
    Replies:
    1
    Views:
    482
    Steve C. Orr, MCSD
    Aug 10, 2003
  2. Replies:
    0
    Views:
    561
  3. Replies:
    1
    Views:
    578
    David
    Apr 24, 2007
  4. soonic
    Replies:
    11
    Views:
    1,827
    soonic
    Jul 27, 2011
  5. Russell
    Replies:
    2
    Views:
    316
    Russell
    Sep 13, 2004
Loading...

Share This Page