Open external links in a frame

Discussion in 'JavaScript' started by scriptreseller, Dec 28, 2007.

  1. #1
    Hi

    i want to open all external links in a frame. I have the frame

    www.domain.com/frame?http://www,google.com

    which works all i need now is some javascript that can make only external links open in the frame.

    all the links are posted by users so this needs to be dynamic.

    Can any one help me

    Thnaks
     
    scriptreseller, Dec 28, 2007 IP
  2. godkillah

    godkillah Guest

    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    thats quite easy to do
    <script>
    //by Godkillah
    
    var linky='http://www.domain.com/frame'
    
    a=document.getElementsBytagName("a")
    for(i=0;i<a.length;i++){
    if(!a[i].href.match(location.hostname)){
    a[i].href=linky+"?"+a[i].href
    }}
    </script>
    Code (markup):
    i think its quite selfexplaining

    hope it helps,
    -Godkillah
     
    godkillah, Jan 6, 2008 IP