Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question about faq216-220

Status
Not open for further replies.

hererxnl

Technical User
Jul 8, 2003
239
US

Sorry, I know that people hate answering this questions pertaining to the "disabling of right clicks" but bear with me. In keeping with the spirit of the FAQ's I found this example posted in 2000. Here's the code so you don't have to see for yourselves:
Code:
<SCRIPT LANGUAGE="JavaScript">
<!-- start hide

document.onmousedown = click;

if (document.layers)
  document.captureEvents(Event.MOUSEDOWN);

function click(e) 
  {
  if (document.all)
    if (event.button == 2)
      {
      document.write(""); // need to do this to "fool" IE
      return false;
      }
  if (document.layers) 
    if (e.which == 3) 
      {
      return false;
      }
  }

// end hide -->
</SCRIPT>

All well and good, I love when I can get an answer from the FAQ's, but after playing with this its definitly not working right. The problem lies in this line:
Code:
document.write(""); // need to do this to "fool" IE

Having played with a few of these scripts it seems IE will not respond to these functions wihout attempting to notify the user. Thus document.write("") or alternatively in other scripts I've seen alter("Something"). Otherwise right clicks still work. I get that. However, as soon as a right click takes place on the page the title of the window changes to the url and the page seems to freeze. Right click more than once and the page goes blank. Does this FAQ need to be re-written for newer browser versions?

Is anyone else having the same problem? Am I crazy? Don't answer that. ;)

 
Try this:

Code:
if (event.button == 2){
    document.open();
    document.write(""); // need to do this to "fool" IE
    document.close();
    return false;
}

*cLFlaVA
----------------------------
[tt]a frickin' twelve-gauge, what do you think?[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 

thanks for the help cLFaVA. Unfortunately the code you posted immediately delivers the broswer a blank version of the page. My testing machine is using IE v.6.0.290...

Haven't loaded NN, FF or Opera on this box.

 

Well I thought I'd post the solution I used which I found deep in these forums. This works perfectly, and silently, with my IE 6:
Code:
function clickIE() {
	if (document.all) return false;
}

function clickNS(e) {
	if(document.layers||(document.getElementById&&!
document.all)) {
		if(e.which==2||e.which==3) return false;
	}
}

if(document.layers) {
	document.captureEvents
(Event.MOUSEDOWN);document.onmousedown=clickNS;
} else {
	document.onmouseup=clickNS;document.oncontextmenu=clickIE;
}
document.oncontextmenu=new Function("return false")

Haven't tried it with NN, FF or Opera yet. Hope it helps someone else. Thanks to Coogan for posting it in another thread.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top