SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript Functions and links

    Hello,

    I wrote a funtion for all my <a href=...> tags.
    If I use the function, it looks like this:
    <a href="test.html" onFocus="myfunction()">

    What I want is to automatically add myfunction() to all the links on a page. So I don't want to add onFocus=blablabla each time when I link to another page.

    Any suggestions?

  2. #2
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This may not work but it is he only thing I could come up with.

    There is an element grabber called

    document.getElementByTagName('a')

    you can find info on this here

    http://www.webreference.com/programm...pting/1/3.html

    use this like this

    Code:
    document.getElementByTagName("a").onfocus=fucntion;
    Now to get this to work in all browsers definately read up on advanced event handling. I can't find th article for IE but this is for netscape 6.0.

    http://www.webreference.com/js/column74/


    Hope this works. In theory it should
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  3. #3
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've already tried that, but it seems it doesn't work in MSI6

    A simple try:

    Code:
    <script>
    
    var nule = black;
    document.getElementByTagName("a").style.backgroundColor=nule;
    
    </script>
    Unfortunately, this doesn't work

  4. #4
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    document.getElementByTagName returns an array, so if you iterate through each element it'll work.
    ck :: bringing chris to the masses.

  5. #5
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I recently posted a similar request on another forum for help with a catch-all function such as the one you are looking for...

    My request was for a script that would kill all activation of the Internet Explorer image link focus border on a page.
    I knew how to do it on a link by link basis, but wanted to add it to existing sites so wanted something that could go into the head tag with only minimal addition to the code.

    He posted this:
    -------------------


    function unblur() {
    this.blur();
    }

    function getLinksToBlur() {
    if (!document.getElementById) return
    links = document.getElementsByTagName("a");
    for(i=0; i<links.length; i++) {
    links[i].onfocus = unblur
    }
    }

    and then put in the body tag:

    <body onload="getLinksToBlur();">

    the onload event is triggered after the page is loaded. You cannot put it just in the <head> section because if the code is executed at this point you won't have any "A" tags to 'unblur'

    --------

    While not knowing a great deal about what is happening in this script, I'm pretty sure both parts can be adapted to perform your function quite easily.

    It worked a treat for me

    Hope this helps
    New Plastic Arts: Visual Communication | DesignateOnline

    Mate went to NY and all he got me was this lousy signature

  6. #6
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Anarchos
    document.getElementByTagName returns an array, so if you iterate through each element it'll work.
    Man i always forget that. Sheesh......
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •