1

I want to disabled the hyperlink after it was opened in new tab using one right click, so that I call the onmouseup event and checked for right click and call disable function. But the disable functionality not work here. I don't want to hide the link, I just want to disable the link.

This is the HTML:

<html>
<body>
<a id="1" href="link1.html" onmouseup="if(event.button==2){disable(this.id)}">link_1</a>
<a id="2" href="link2.html" onmouseup="if(event.button==2){disable(this.id)}">link_2</a>
</body>
</html>
    

and JavaScript,

<script>
function disable(get)
{
 document.get.style.display="block";
}
</script>

Can any one have idea on this?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user1345801
  • 59
  • 2
  • 5
  • In case you were not aware, it is invalid to have an element id starting with a number in HTML4.01. This is not the case for HTML5 compatible documents. Please see [here](http://mathiasbynens.be/notes/html5-id-class) for a longer explaination. – andyb May 16 '12 at 08:01

1 Answers1

1

I'm not exactly sure what you want to accomplish by setting display:block on the <a> but the error you should be seeing in the browser is a JavaScript one because you document.get is incorrect.

Since you are passing the element id to the disable() function you could use

document.getElementById(get).style.display = 'block';

to set the display property.

Or just pass this instead like so:

HTML

<a id="1" href="link1.html" onmouseup="if(event.button==2){disable(this)}">link_1</a>
<a id="2" href="link2.html" onmouseup="if(event.button==2){disable(this)}">link_2</a>

JavaScript

function disable(theLink) {
    theLink.style.display="block";
}​

To address the disable problem, setting display:block will not disable the link. You might want to look at adding an onclick function to consume the click event as demonstrated at Disable link using javascript and/or modifying the <a> style to indicate that it is disabled, for example setting the color to grey.

Community
  • 1
  • 1
andyb
  • 43,435
  • 12
  • 121
  • 150