PDA

View Full Version : Opening https links in new window



miketosetto
08-18-2013, 01:14 AM
1) Script Title:
Open offsite links in new window script

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

3) Describe problem:
Open offsite links in new window script is amazing, but it doesn't seem to work with https links. Works perfectly with http links.

Is it possible to modify the JS file to allow this? If so, would you be so kind as to show me what line and where?

Hoping you can help.

Cheers

Mike

jscheuer1
08-18-2013, 02:38 AM
In the ddwindowlinks.js script, line #25:


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

Using a text only editor like NotePad, change that to:


if (all_links[i].hostname.search(rexcludedomains)==-1 && /^http/.test(all_links[i].href))

Save and use that version. It will work for both http and https, any href that begins with http and is not excluded.

The browser cache may need to be cleared and/or the page refreshed to see changes.

miketosetto
08-19-2013, 12:48 PM
Thanks so much for getting back to me. I really appreciate it.

Your solution is almost perfect except now it opens local pages in new windows. For example local pages target _blank rather than _self.

Is there a work around for this?

Thanks :)

Mike
www.miketosetto.com

jscheuer1
08-19-2013, 03:29 PM
Ah, I see, the demo page neglects to clearly tell that you have to edit the excludedomains property in ddwindowlinks.js.

Again using NotePad or similar, change (from the top of the file):


//Open offsite links in new window script- http://www.dynamicdrive.com/
//Created: August 28th, 2007'

var ddwindowlinks={
//1)Enter domains to be EXCLUDED from opening in new window:
excludedomains: ["dynamicdrive.com", "google.com"],

//2) Target for links that sho . . .

to:


//Open offsite links in new window script- http://www.dynamicdrive.com/
//Created: August 28th, 2007'

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

//2) Target for links that sho . . .

Save and use that file.

The browser cache may need to be cleared and/or the page refreshed to see changes.

miketosetto
08-19-2013, 08:55 PM
Hi John, thanks for getting back to me so quickly and thanks again for taking the time to help.

Your solution works a treat.

Cheers

Mike