On hyperlinks in the right click menu, how can I remove or hide the Open In New Tab and Open In New Window options?
for example
<a href="#" onclick="asd">foo</a>
On hyperlinks in the right click menu, how can I remove or hide the Open In New Tab and Open In New Window options?
for example
<a href="#" onclick="asd">foo</a>
Not sure why you'd want to do this but it can be done by moving the href
to a data-href
attribute, then remove the href
and add a click handler. The onclick will read the data-href
and redirect.
var links = document.getElementsByTagName("a");
for(var i=0; i<links.length; i++){
links[i].setAttribute("data-href", links[i].getAttribute("href"));
links[i].removeAttribute("href");
links[i].onclick = function(){
window.location = this.getAttribute("data-href");
};
}
The right click menu shows:
You can use javascript link instead of plain html ones. Just do href="javascript:void(0)" and handle the click event to redirect the page. This won't remove the option of opening in another tab but will make sure the page doesn't actually open up when tried.
Also instead of an HTML tag, you can instead use another tag like and give it a cursor:pointer css property and jquery onclick to make it work like a link. This will completely remove the option "open in another tab" from context menu.
you can do it using following code.
<script language="javascript">
$("a").click(function(event)
{
if(event.button==2)
{
return false;
}
});
</script>