PHP/Javascript: Make certain links open in a new window?

Status
Not open for further replies.

Darlos

Active Member
212
2011
9
0
Does anyone know a code for making a certain link open in a new window automatically?
Example:
All "wjunction.com" links will open in a new window

I know I can do this manually but I probably have over 1000+ links in my blog that doesn't have a target="_blank" tag.
 
6 comments
just change the title & link to your choice & add it to your website & click the link ,, then it will be opened in new tab
 
@NiKE,

Sorry but I already know that code. I need one that will automatically add a code like that in for example, "wjunction" list of links.

You want to open each and every external link in a new tab?
Yep! but not me, my visitors.
 
Ok! Try this code, this will make all links add target="_blank" on load of the page

PHP:
<html>
<head>
<title>Add target _blank in all Links by Javascript</title>

<script type="text/javascript">
window.onload=addtargetblankinalllinks ; // add the function on load of the page
function addtargetblankinalllinks() {
var links = document.getElementsByTagName('a');
for(i in links)
    links[i].target="_blank";
}
</script>

</head>
<body>
<a href="http://www.dl4everything.com">DL4EVERYTHING</a><br />
<a href="http://www.soft2050.in">Soft2050</a><br />
<a href="http://www.google.com">Google</a><br />
<a href="http://www.yahoo.com">Yahoo</a><br />
<a href="http://www.facebook.com">Facebook</a><br />
All Links will open in new tab even the links don't have any target _blank
</body>
</html>

Eg Link for testing: http://pastehtml.com/view/bmbwg4vvx.html
 
Status
Not open for further replies.
Back
Top