Somewhere on your page (should be true
/false
):
var newWindow = <?=$newWindow;?>
Then do (jQuery, just concept though):
$('a').bind('click', function(event){
if(newWindow){
event.preventDefault();
window.open($(this).attr('href'));
}
});
There are a few ways of doing it, but this one came to mind first. This obviously requires you to also handle relative links - so keep that in mind.
Edit: Due to @durbnpoisn giving me greif, here's the code ready for you to drop into your site:
Link:
<a id="toggle-new-tab">Turn on/off new window</a>
JS:
var newWindow = false;
document.getElementById('toggle-new-tab').onclick = function(){
newWindow = !newWindow;
}
var links = document.getElementsByTagName('a');
for(var i = 0; i < links.length; i++){
if(links[i].href !== '')
links[i].onclick = newWindowHandler;
}
function newWindowHandler(event){
if(newWindow){
event.preventDefault();
window.open(event.target.href);
}
}