PDA

View Full Version : Opening All External Links In "_blank" Page



BawA
05-10-2004, 09:17 AM
is there any script to set all external links to open in new page?

2nd gen noob
05-10-2004, 09:23 AM
http://www.pageresource.com/html/newwin.htm

I.am
05-10-2004, 09:26 AM
<a target="_blank" href="http://www.domain.com">Link</a>


Btw, may I suggest using google before asking. We are no substitute for the power of google...

2nd gen noob
05-10-2004, 09:29 AM
Originally posted by I.am@10 May 2004 - 09:34

<a target="_blank" href="http://www.domain.com">Link</a>


Btw, may I suggest using google before asking. We are no substitute for the power of google...
Indeed. There aren't many questions asked on this forum to which Google has no answer http://www.mcbriens.net/liam/img/smilies/notworthy.gif

BawA
05-10-2004, 09:30 AM
setting one link a time is easy but if u have lots of links that u want them to open in new page will be hard to set them one by one so i want some kind of code or script that sets all external links to open in new page.

2nd gen noob
05-10-2004, 09:33 AM
Originally posted by bawa@Klite_user@10 May 2004 - 09:38
setting one link a time is easy but if u have lots of links that u want them to open in new page will be hard to set them one by one so i want some kind of code or script that sets all external links to open in new page.
Find and replace :)

I.am
05-10-2004, 09:45 AM
To open all links of your page in a new window,

Put this between <head> </head>


&#60;base target=&#34;main&#34;&#62;


Use your <head> wisely. :P

BawA
05-10-2004, 09:48 AM
thats easy but i dont want ma own page links like menu links to open in new page only external links like a link to a other site to open in new page

2nd gen noob
05-10-2004, 09:56 AM
Originally posted by bawa@Klite_user@10 May 2004 - 09:56
thats easy but i dont want ma own page links like menu links to open in new page only external links like a link to a other site to open in new page
Post your source...

I.am
05-10-2004, 10:04 AM
I can write a script that opens the specified url in the new window whenever you call it. But its useless. You still have to give the function in onclick of the link so why not just take a step back and add the target as well.

Btw, FYI in html 4.01 target field is deprecated. They added a "rel" instead.

eg:

&#60;a href=&#34;page.html&#34; rel=&#34;external&#34;&#62;Page&#60;/a&#62;

BawA
05-10-2004, 05:30 PM
Originally posted by 2nd gen noob+10 May 2004 - 13:41--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td>QUOTE (2nd gen noob @ 10 May 2004 - 13:41)</td></tr><tr><td id='QUOTE'> <!--QuoteBegin-bawa@Klite_user@10 May 2004 - 09:38
setting one link a time is easy but if u have lots of links that u want them to open in new page will be hard to set them one by one so i want some kind of code or script that sets all&nbsp; external links to open in new page.
Find and replace :) [/b][/quote]
there is something wrong with " Search and Replace" function, here what i do:

I open all my wanted documents and then search for a script under "all open documents" and i search and it finds all the scripts but when i click replace all i get "0 from 140 found", how could it be when it finds in search.

DRACOJOE2
05-16-2004, 01:53 PM
Here is a Open All Offsite Links In New Window script from dynamicdrive. Edit it where it tells ya to and add it to the body section of your page.

&#60;script language="JavaScript1.2">
&#60;&#33;--

//Open offsite links in new window option- By Jessica Hammer
//Heavily modified by Dynamic Drive
//Visit http://www.dynamicdrive.com for this script

//1)Enter domains to be EXCLUDED from opening in new window:
var excludedomains=["dynamicdrive.com", "javascriptkit.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 (&#33;auto)
document.write(&#39;<form name="targetmain"><input type="checkbox" name="targetnew" checked onClick="dynamiclink()">Open off-site links in new window</form>&#39;)

function dynamiclink(){

if (auto||(&#33;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:")&#33;=-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

// --&#62;
</script>

BawA
05-16-2004, 02:03 PM
Finaly somebody understood wtf am talking about, thanks ma8 ;)