SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru kili's Avatar
    Join Date
    Jan 2004
    Location
    Damn I need a Crap
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up What does this script do

    Hi Guys can anyone tell me what the script below does I know it opens the link in a new window but I was under the impression that the script also prevented loss of page rank due to external links. I'm not a coder can anyone dechiper this for me please and tell me exactly what it does

    Cheers Kili


    //Open offsite links in new window option

    //1)Enter domains to be EXCLUDED from opening in new window:
    var excludedomains=["MYDOMAIN.com"]

    //2)Automatically open offsite links in new window? (1=yes, 0 will render a checkbox for manual selection)
    var auto=1

    var excludedomains=excludedomains.join("|")
    rexcludedomains=new RegExp(excludedomains, "i")

    if (!auto)
    document.write('<form name="targetmain"><input type="checkbox" name="targetnew" checked onClick="dynamiclink()">Open off-site links in new window</form>')

    function dynamiclink(){

    if (auto||(!auto&&document.targetmain.targetnew.checked)){
    for (i=0; i<=(document.links.length-1); i++) {
    if (document.links[i].hostname.search(rexcludedomains)==-1&&document.links[i].href.indexOf("http:")!=-1)
    document.links[i].target="_blank"
    }
    }
    else
    for (i=0; i<=(document.links.length-1); i++) {
    if (document.links[i].hostname.indexOf(mydomain)==-1)
    document.links[i].target=""
    }
    }

    if (auto)
    window.onload=dynamiclink

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    This script doesn't help stop PageRank transfer. All it does is ask you whether or not links should be opened in a new window.

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var excludedomains=["MYDOMAIN.com"]

    var auto=1 //no checkbox, set links target="_blank" automatically (1 equals true in JS)

    var excludedomains=excludedomains.join("|") //put excluded domains in one long string with "|" separator
    rexcludedomains=new RegExp(excludedomains, "i") //make it into a case-insensitive regular expression (for easy matching)

    if (!auto) //using checkbox to set link target, so generate HTML for mini-form
    document.write('<form name="targetmain"><input type="checkbox" name="targetnew" checked onClick="dynamiclink()">Open off-site links in new window</form>')

    function dynamiclink(){ //called on page load or on checkbox being checked/unchecked

    if (auto||(!auto&&document.targetmain.targetnew.checked)){ //new window option desired
    for (i=0; i<=(document.links.length-1); i++) { //loop through all link objects
    if (document.links[i].hostname.search(rexcludedomains)==-1 //if not excluded...
    &&document.links[i].href.indexOf("http:")!=-1) //and has an http scheme assigned...
    document.links[i].target="_blank" //then set Link.target for new window
    }
    }
    else //otherwise
    for (i=0; i<=(document.links.length-1); i++) { //loop
    if (document.links[i].hostname.indexOf(mydomain)==-1) //presumably 'not this site' (you left 'mydomain' out!)
    document.links[i].target="" //open in same window
    }
    }

    if (auto)
    window.onload=dynamiclink //no checkbox needed
    ::: certified wild guess :::

  4. #4
    SitePoint Guru kili's Avatar
    Join Date
    Jan 2004
    Location
    Damn I need a Crap
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Guys seems a lot of code for such a simple task.


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
  •