Stop New Tab from Opening

How to disable the 'Open Link in New Tab' in the browser?

Have solved the main issue now, quite easily as it turned out just by passing the query string of the href to an ajax function.

I probably should have explained in my question that what I wanted was intended only as a temporary measure. Anyway thanks for all the comments.

Preventing pages being open in a new tab/window

Instead of

<a href="http://stackoverflow.com">link</a>

use

<a href="javascript:void(0);" onclick="javascript:window.location.href='http://stackoverflow.com';">link</a>

Middle mouse click opens this location in the same tab, right click -> open in new tab opens about:blank page.


When you can't edit every link manually you can use this script:

for(var els = document.getElementsByTagName('a'), i = els.length; i--;){
els[i].href = 'javascript:void(0);';
els[i].onclick = (function(el){
return function(){
window.location.href = el.getAttribute('data-href');
};
})(els[i]);
}

and instead of <a href="..."> use <a data-href="...">.


Going further, you may change script above to following:

for(var els = document.getElementsByTagName('a'), i = els.length; i--;){
var href = els[i].href;
els[i].href = 'javascript:void(0);';
els[i].onclick = (function(el, href){
return function(){
window.location.href = href;
};
})(els[i], href);
}

this way links stay the same <a href="...">, but if user has disabled JavaScript, links may be opened in another tab/window.

How to prevent to open new tab when I drag and drop image on the Chrome browser in JavaScript?

You should add preventDefault() on all dragover and drop events handlers.
Example:

window.addEventListener("dragover",function(e){
e = e || event;
e.preventDefault(); <=================
},false);
window.addEventListener("drop",function(e){
e = e || event;
e.preventDefault(); <=================
},false);

More Useful link here for React

Here is the same question for drag and drop

How to stop Microsoft Edge opening Bing links in a new tab

Open https://www.bing.com/account/general#settings_results in Microsoft Edge, and you will have to disable the "Open links from search results in a new tab or window" from the 'Results' section. And click 'Save'.



Related Topics



Leave a reply



Submit