Post links in new window/tab

Discussion in 'HTML & Website Design' started by mcdeere02, Aug 5, 2009.

Thread Status:
Not open for further replies.
  1. #1
    I need JavaScript that would change all the links on my site that aren't linked to my site, to open in new window/tab.

    Thanks.
     
    mcdeere02, Aug 5, 2009 IP
  2. gareth_gillman

    gareth_gillman Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    why not use html ?

    <a href="link.html" target="_blank">Link Text</a>
     
    gareth_gillman, Aug 5, 2009 IP
  3. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    437
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Dan Schulz, Aug 5, 2009 IP
  4. osmasters

    osmasters Well-Known Member

    Messages:
    453
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    100
    #4
    May be you have other problem.

    function decidewindow()
    {
    if(this.href=='yoursite.com') //if yoursite.com/xyz.html then search yoursite.com in this.href by other function.
    {
    return true;
    } else {
    window.open(this.href,'newwindow');
    return false;
    }
    return false;

    }


    <a href='yoursite.com' onclick='return decidewindow(this);'></a>
    <a href='othersite.com' onclick='return decidewindow(this);'></a>

    I hope this help you.
     
    osmasters, Aug 5, 2009 IP
  5. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    437
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It's better to have the event handlers outside the HTML - no JavaScript should be inlined whatsoever.
     
    Dan Schulz, Aug 5, 2009 IP
  6. gareth_gillman

    gareth_gillman Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i always put my js in a .js file, and call it at the end of the file just before the </body> tag
     
    gareth_gillman, Aug 5, 2009 IP
Thread Status:
Not open for further replies.