PDA

View Full Version : Offsite Links in New Window Script



bigsite
11-29-2007, 04:55 AM
1) Script Title: Offsite Links in new Window

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex8/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:confused:

jscheuer1
11-29-2007, 01:54 PM
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:


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:


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)
},

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.

bigsite
12-01-2007, 10:25 PM
Error: [Exception... "Component returned failure code: 0x804b000a [nsIDOMNSHTMLAnchorElement.hostname]" nsresult: "0x804b000a (<unknown>)" location: "JS frame :: http://www.bigsite.us/catalog/catalog_product.php?&gcst=hp%20compaq%20desktop%20pc&gcstype= :: anonymous :: line 214" data: no]
Source File: http://www.bigsite.us/catalog/catalog_product.php?&gcst=hp%20compaq%20desktop%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......

bigsite
12-01-2007, 10:51 PM
error console in firefox shows

Error: XML filtering predicate operator called on incompatible RegExp
Source File: http://www.bigsite.us/catalog/catalog_product.php?&gcst=hp%20compaq%20desktop%20pc&gcstype=
Line: 214

and

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

jscheuer1
12-02-2007, 05:38 AM
Your page is in violation of Dynamic Drive's usage terms (http://www.dynamicdrive.com/notice.htm), 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:


<a name=goldencan></a>

an a tag with no href. To fix that, change (oddly enough it is the same line):


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

to:


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.

bigsite
12-02-2007, 07:16 PM
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

bigsite
12-02-2007, 07:18 PM
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........