View Full Version : Force a web page to open in new window/tab???
spiper
01-21-2013, 10:10 AM
Okay, so we all know how to make a hyperlink open in a new window or new tab but...
I have built a website with several pages. But now I would like one particular page to always open in a new window or tab. Can i put something in the coding of this particular page to make it open in a new window or do I really have to go in to every page and amend all the links to this page?
Imagine if I had several hundred pages with thousands of links to this one page, would I really have to change all these links? Please tell me that it isn't so!! :confused:
Help!
Snookerman
01-21-2013, 12:17 PM
You can put <base target="_blank"> in the head section of the page.
spiper
01-21-2013, 02:03 PM
This would make all links (as default) within that page open in a new tab. Unfortunately not what I am after but thanks.
I have a fully functioning website, functioning ok as it is. Every page opens within the same window. But i now need just one specific page 'example.html' to always open in a new tab/window. There is at least one link to this page on every web page. I want this page ONLY to open in a new tab or window. Can I achieve this without going through the whole website and manually changing every link to this page?
Beverleyh
01-21-2013, 02:22 PM
You said in your first post that you have several pages on your website - how many is *several*? If there are only 10 or 20, or even 30, its probably going to be a relatively easy fix to edit them all manually. I've had to manually tweak websites with 50+ pages before and once you get into the swing of find-edit-replace, it doesn't really take that long (probably less time than worrying about finding a workaround too)
If this link forms part of a menu, maybe now would be a good time to think about separating it off as a Server Side Include or php include - it will save you lots of edit-time in future.
Server Side Include : http://www.javascriptkit.com/howto/ssi.shtml
PHP include : http://www.tizag.com/phpT/include.php
jscheuer1
01-21-2013, 02:43 PM
Not really. You could put a script on each page, it could be external, so you would need only one script and if you already have a script that runs on every page, this could simply be added to it:
;(function(){
var re = /example\.htm[$\?#]/;
function targetlink(e){
e = e || event;
var t = e.target || e.srcElement, href;
if(t.href && re.test(href = t.href) || t.parentNode.href && re.test(href = t.parentNode.href)){
window.open(href, '_blank')
e.preventDefault && e.preventDefault();
e.returnValue = false;
}
}
if (document.addEventListener){
document.addEventListener('click', targetlink, false);
}
else if (document.attachEvent){
document.attachEvent('onclick', targetlink);
}
})();
Just change example\.htm$ in the above to the actual name of the page, use the down slash as shown for the . character and the bracketed [$\?#] at the end to indicate the end of the filename.
Of course this will only work if javascript is enabled. Most (like 99%) people do have that.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.