Results 1 to 7 of 7

Thread: Offsite Links in New Window Script

  1. #1
    Join Date
    Nov 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Offsite Links in New Window Script

    1) Script Title: Offsite Links in new Window

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...newwindow2.htm

    3) Describe problem: I have successfully implemented the offsite links script on my web site. DD YOU ARE A GREAT RESOURCE! However, the script fails to recognize the link target variable when it is a URL page followed with a string, and only in Firefox...IE is fine.

    for example 'http://anothersite.com/page.html' will work just fine, but:

    the example 'http://anothersite.com/page.html?ext=123&search=test' just opens up in the same window, and not a new window

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    This is a little complex to test, so I'm just going to guess that FF is confusing the method search in the below with the term search:

    Code:
    assigntarget:function(){
    	var rexcludedomains=new RegExp(this.excludedomains.join("|"), "i")
    	var all_links=document.getElementsByTagName("a")
    	if (this.mode=="auto" || (this.mode=="manual" && this.togglebox.checked)){
    		for (var i=0; i<=(all_links.length-1); i++){
    			if (all_links[i].hostname.search(rexcludedomains)==-1 && all_links[i].href.indexOf("http:")!=-1)
    				all_links[i].target=ddwindowlinks.linktarget
    		}
    	}
    	else{
    		for (var i=0; i<=(all_links.length-1); i++)
    			all_links[i].target=""
    	}
    	if (this.mode=="manual" && this.persist)
    		this.setCookie("dlinktarget", (this.togglebox.checked)? "yes" : "no", 30) //remember user setting for 30 days (set to -1 then reload page to erase cookie)
    },

    If that is the case, this will fix it:

    Code:
    assigntarget:function(){
    	var rexcludedomains=new RegExp(this.excludedomains.join("|"), "i")
    	var all_links=document.getElementsByTagName("a")
    	if (this.mode=="auto" || (this.mode=="manual" && this.togglebox.checked)){
    		for (var i=0; i<=(all_links.length-1); i++){
    			if (!rexcludedomains.test(all_links[i].hostname) && all_links[i].href.indexOf("http:")!=-1)
    				all_links[i].target=ddwindowlinks.linktarget
    		}
    	}
    	else{
    		for (var i=0; i<=(all_links.length-1); i++)
    			all_links[i].target=""
    	}
    	if (this.mode=="manual" && this.persist)
    		this.setCookie("dlinktarget", (this.togglebox.checked)? "yes" : "no", 30) //remember user setting for 30 days (set to -1 then reload page to erase cookie)
    },
    Edit: However, I did do some testing, and your example URL's both opened in a new window in FF, even with the original coding. So, if you need more help:

    Please post a link to the page on your site that contains the problematic code so we can check it out.
    Last edited by jscheuer1; 11-29-2007 at 02:18 PM. Reason: add info
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Nov 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question error console message for you......chg did same thing

    Error: [Exception... "Component returned failure code: 0x804b000a [nsIDOMNSHTMLAnchorElement.hostname]" nsresult: "0x804b000a (<unknown>)" location: "JS frame :: http://www.bigsite.us/catalog/catalo...%20pc&gcstype= :: anonymous :: line 214" data: no]
    Source File: http://www.bigsite.us/catalog/catalo...%20pc&gcstype=
    Line: 214

    this error occurs as the source file loads in an iframe inside the main page.....i am trying to launch the offsite links from within the iframe.....as before, this works if the location is filename only without any string info following......

  4. #4
    Join Date
    Nov 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default additional errors

    error console in firefox shows

    Error: XML filtering predicate operator called on incompatible RegExp
    Source File: http://www.bigsite.us/catalog/catalo...%20pc&gcstype=
    Line: 214

    and

    Error: uncaught exception: Permission denied to call method Location.toString

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Your page is in violation of Dynamic Drive's usage terms, which, among other things, state that the script credit must appear in the source code of the page(s) using the script. Please reinstate the notice first.


    OK, that's not the real problem. And it has nothing to do with the query appended to the href. It has to do with:

    HTML Code:
    <a name=goldencan></a>
    an a tag with no href. To fix that, change (oddly enough it is the same line):

    Code:
    if (all_links[i].hostname.search(rexcludedomains)==-1 && all_links[i].href.indexOf("http:")!=-1)
    to:

    Code:
    if (all_links[i].href && all_links[i].hostname.search(rexcludedomains)==-1 && all_links[i].href.indexOf("http:")!=-1)
    There were other errors (not with this script) on the page, so there could be other problems.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Nov 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i apologize, i have been editing the script and might have deleted the code credits during live testing............

    .............if this doesn't do it, is there a way to detect the offsite url AND remove the string....like with a -uri.arg

  7. #7
    Join Date
    Nov 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    as to the other errors btw........i know that my pages need alot of cleaning up, right now it is more of "if it works don't break it" until it is 100% complete........

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
  •