target="blank"

Discussion in 'HTML & Website Design' started by cyberpunk_33, Sep 5, 2007.

  1. #1
    Hello All!

    I have a question about target="blank". I'm sure most of us know that it no longer conforms with the xhtml standards, but I know there is a way to make windows pop up in a seperate window using some java code. Now, do realize that I have searched the internet for an answer and found many solutions, but I don't understand how to apply them. Could someone please break it down for me?

    I know it has something to do with:

    <head><script type="text/javascript" src="/external.js"></script></head>

    <a href="document.html" rel="external">external link</a>

    Thank you in advance -:)
    Cyberpunk
     
    cyberpunk_33, Sep 5, 2007 IP
  2. itssangy

    itssangy Peon

    Messages:
    135
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    in your external.js file, you'd have to insert this 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";
     }
    }
    window.onload = externalLinks;
    
    Code (markup):
    hope that helps
     
    itssangy, Sep 6, 2007 IP
  3. cyberpunk_33

    cyberpunk_33 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the speedy reply - I guess my real question is how to implement that code into external.js? I'm new to this stuff...lol :)


    Thanks,
    Cyber
     
    cyberpunk_33, Sep 6, 2007 IP
  4. soulscratch

    soulscratch Well-Known Member

    Messages:
    964
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    155
    #4
    What if the value of "rel" is not only 'external' ? What if you have other functions firing off on window load?

    Anyway for the original poster..

    <head>
    <script type="text/javascript" src="external.js"></script>
    </head>

    ^ The minimum markup required. In your external.js file, paste that function in assuming you're not using any other functions onload and it should work..
     
    soulscratch, Sep 6, 2007 IP
  5. cyberpunk_33

    cyberpunk_33 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    OK sounds good - Where do I get external.js? Do I have to create a text file and the copy the code into the file and save it as external.js? Like I said, I'm new to this stuff and am learning xhtml. Sorry for all the annoying questions -


    Cyber
     
    cyberpunk_33, Sep 6, 2007 IP
  6. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yes, you create a text file, save it with the .js extension and then put that on your server, referencing it in your Web page.
     
    Dan Schulz, Sep 7, 2007 IP
  7. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #7
    What?? This serves no purpose other than being able to say your pages are valid (which is an overrated thing anyway and gives too many people a false sense of pride that their web site is coded well). Also, it relies on JavaScript and requires the page to load before applying the changes. Why not just use window.open if you are going to rely on JS.

    I mostly use page overlays instead of popups but when I do use popups, I use target="_blank" and an "onclick" event with a "return false;" to nullify the target attribute for the majority with JS enabled. That way, those with JS get to use the window.open popups with more options and non-JS users still get a popup. I know if my sites are usable, accessible, semantic etc. so a validator complaining about some tiddly "target" attribute is not an issue.
     
    krt, Sep 7, 2007 IP