Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Dec 2008
    Posts
    37
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Add REL to LI onClick?

    I am using a JavaScript to add a 'blank' target to any links that have 'external' specified in the REL. This is working great, but on some of the links, I need to give the user the ability to click the surrounding <li> item as well.

    So my regular link looks like this:

    Code:
    <li><a rel="external" href="http://www.google.com">Google</a></li>
    I need to figure out how to add the REL to the onclick in the LI

    Code:
    <li onclick="location.href='http://www.google.com/';"><a rel="external" href="http://www.google.com">Google</a></li>
    The JavaScript I am using is here:
    Code:
    function externalLinks() { 
     if (!document.getElementsByTagName) return; 
     var anchors = document.getElementsByTagName("a"); 
     for (var i=0; i<anchors.length; i++) { 
       var anchor = anchors[i]; 
       if (anchor.getAttribute("href") && 
           anchor.getAttribute("rel") == "external") 
         anchor.target = "_blank"; 
     } 
    }

    THANKS FOR ANY ADVICE! I can't seem to find any instructions about how to insert this REL option....

  • #2
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    why not just display your <a> block so that it just fills in the entire <li>?

  • #3
    New Coder
    Join Date
    Dec 2008
    Posts
    37
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I've got a li:hover working on the entire LI....

    http://adamfialkov.com/index_new.php

  • #4
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    Then just use:
    Code:
    <li onclick="window.open('http://www.google.com/');"><a rel="external" href="http://www.google.com">Google</a></li>

  • #5
    New Coder
    Join Date
    Dec 2008
    Posts
    37
    Thanks
    1
    Thanked 0 Times in 0 Posts
    That works, but it causes two windows to pop open when the user clicks on the link! I think I am actually just going to skip the onClick for these particular links and force the user to actually hit the hyperlinked text....usability-wise, that will be better.

    Thanks for the help!

  • #6
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    you could also use this which would solve your problem
    Code:
    <li onclick="this.getElemetsByTagName('a').click();"><a rel="external" href="http://www.google.com">Google</a></li>

  • #7
    New Coder
    Join Date
    Dec 2008
    Posts
    37
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hmmm - gave that a shot, but no dice....


  •  

    Posting Permissions

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