homepage Welcome to WebmasterWorld Guest from 54.211.100.183
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Disabling Mouse
how to?
fashezee

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 780 posted 12:54 am on Feb 19, 2003 (gmt 0)

I would like to disable both right and left click of a mouse on a certain page?

How can I do this?

 

Chuma

10+ Year Member



 
Msg#: 780 posted 1:38 am on Feb 19, 2003 (gmt 0)

There are methods to do this but people will always find a way to circumvent any protection mechanisms, so it is probably not advisable to do this.

Thanks.

mahlon

10+ Year Member



 
Msg#: 780 posted 1:41 am on Feb 19, 2003 (gmt 0)

yep!

tedster

WebmasterWorld Senior Member tedster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 780 posted 2:33 am on Feb 19, 2003 (gmt 0)

fasheze, what on earth are you up to here?

kevinpate

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 780 posted 2:49 am on Feb 19, 2003 (gmt 0)

Wouldn't that tactic be tantamount to a flashing neon sign that says "HEY, there's something on this page I'm not wanting you to know about?" or "Hey, just you try to copy my stuff, go ahead, I dare ya, cause you can't!"

In the first instance, you're signaling your visitor he or she is not to be trusted.

In the second, you're challenging someone who might not have given a thought to prying itno your stuff to not only attempt to bypass your effort, but pass the site on to others as a "lol, let's rock this guy's 'security' just for grins and giggles."

Neither seems a good idea to me, but hey, it's your site.
Good luck to you if you find a way to go that route.

DrDoc

WebmasterWorld Senior Member drdoc us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 780 posted 5:51 am on Feb 19, 2003 (gmt 0)

In any case, you will only be able to successfullly accomplish this in IE and NN, and this only as long as the user leaves JavaScript enabled.

Anyway, you should be able to find something helpful if you do a site search on "disable right-click," "disable view source," or "protect source code"

Not that I can think of why you would want to do this. But that's none of my business ;)

tedster

WebmasterWorld Senior Member tedster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 780 posted 7:27 am on Feb 19, 2003 (gmt 0)

Well, to be fair to fashezee, you can develop HTML applications for a "closed audience" (intranet, CD, etc.) that end up with very odd requirements -- things you would never think of doing on a general public web page.

c3oc3o

10+ Year Member



 
Msg#: 780 posted 1:02 pm on Feb 19, 2003 (gmt 0)

Try www.slackerhtml.com/javascript/misc/norightorleft.html
... and have fun trying to copy the source code :-)

fashezee

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 780 posted 1:30 pm on Feb 19, 2003 (gmt 0)

All your concerns are understood, however the site is for a closed audience.

It's for young school kids, teacher would like to put some reference material online,
however kids may just copy/paste. I'm using frames, so the navbar will be active within the top frame,
the page with the content is what I need to protect.

Some kids may find a way around it, however - most won't.

DrDoc

WebmasterWorld Senior Member drdoc us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 780 posted 7:55 pm on Feb 19, 2003 (gmt 0)

Then you might be interested in this little thingy. It will "prevent" not only right and left clicks, but also prevent selecting the text:

<html>
<body>
<script language="JavaScript">
<!--
stop=1;
function IE1(){
if(event.button==2){ }
}
// Mouse right-click stopped in Internet Explorer 4+
function IE2(){
if((event.keyCode==121 && event.shiftKey==true) ¦¦ event.keyCode==93){ }
}
// The use of Shift-F10 and the 'Context Menu' key stopped in Internet Explorer 4+
function IE3(){
event.cancelBubble=true;
event.returnValue=false;
}
// The famous mouse double-click getaround stopped in Internet Explorer 4+
function IE4(){
if(stop==1){
event.returnValue=false;
}
}
// Page content selection stopped in Internet Explorer 4+
function NN1(e){
if(e.which==3){return false;}
}
// Mouse right-clicks, Shift-F10, and the 'Context Menu' key stopped in Netscape 3+
function NN2(){
if(stop==1){
return false;
}
}
// Page content selection stopped in Netscape 3+

if(document.layers){
window.captureEvents(Event.MOUSEDOWN);
window.onmousedown=NN1;
window.onselectstart=NN2;
}
if(document.all){
document.onmousedown=IE1;
document.onkeydown=IE2;
document.oncontextmenu=IE3;
document.onselectstart=IE4;
}
//-->
</script>
<table width=450>
<tr>
<td>
<div align="justify">
<font size=5><b>No right-clicks or text copying!</b></font><br>
<br>
This script supposedly stops right-clicks and text selections in both Internet Explorer (version 4+) and Netscape (version <6). Try using the right mouse button, Shift-F10, and/or the Context Menu key. Also, try selecting any portion of this text. If the script works the way it is supposed to, you will only be able to select text in the form field below.</div>
</td>
</tr>
</table><br>
<form name="testform">
<input type="Text" value="You CAN select the text in this field" name="field" onfocus="stop=0;" onblur="stop=1;" size=50><br>
<input type="Text" value="You CAN NOT select the text in this field" name="field2" size=50><br>
<br>
<input type="Button" onclick="document.testform.field.select();" value="Select the text in the first field">
This button does not work<br>
<input type="Button" onclick="stop=0;document.testform.field.select();stop=1;" value="Select the text in the first field">
This button works<br>
</form>
</body>
</html>

And, you might want to make sure the link pointing to the page looks something like:

<a href="#" onclick="framename.location.href='blah.html'">Link text</a>

That way they can't open the link in a new window ;)

fashezee

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 780 posted 8:05 pm on Feb 19, 2003 (gmt 0)

Thanks!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved