aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Disable Right Click,View source and save as Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Disable Right Click,View source and save as" Watch "Disable Right Click,View source and save as" New topic
Author

Disable Right Click,View source and save as

Ashish Agarwal
Ranch Hand

Joined: Dec 02, 2000
Posts: 36
I want to disable right click, Save as and view source in Netscape 6 and IE 5.5. Can anybody tell me how to do it.
TIA
Ashish Agarwal
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Ashish
I'm not sure there is a reliable way to do that. I've seen some hacks but none that work in everything - do a search on this forum for previous discussions. The biggest problem is that there are multiple ways to do those things not using the mouse.
Dave


Dave
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I'd have to agree. I had a bit of a think and the solutions would definitely be "hacks". They wouldn't work well or consistantly or stably and you'd just end up annoying you users.
Unfortunately this is not what HTML is for and you'd essentially be "breaking the rules".
Also, you'de most likely have to rewrite your code from scratch every time a sub-version was released to keep it working.
One bad solution I came up with is to provide the relevant pages as non-printable PDF docs. The user could save the PDFs on their local machines but would not be able to view the "underlying content" or print the data or separate the pictures. It's a bit heavy tho...
Dave.
Ashish Agarwal
Ranch Hand

Joined: Dec 02, 2000
Posts: 36
Dear friends,
Thanks for your replies,I have written some code where I'm disabling right mouse click and hiding the MenuBar altogether. I know there are ways to get around it but for novice users it will work. My problem now is that this is working for Netscape6.0 but not for IE5.5. For IE5.5 it show error that window.menubar is not an object. Can anybody help on this.
I have changed onClick to oClick in my code as Javaranch does not allow onClick to be posted. Plese make it onClick when u copy and paste the code.
--------------------------------------------------
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<script language="JavaScript">
window.menubar.visible=false;

function disableMenu(){
window.menubar.visible=false;

}
function enableMenu(){
window.menubar.visible=true;

}

</script>
</head>
<body bgcolor="#FFFFFF">
<script language="JavaScript">
document.oncontextmenu = function(){return false}
if(document.layers) {
window.captureEvents(Event.MOUSEDOWN);
window.onmousedown = function(e){
if(e.target==document)return false;
}
}
else {
document.onmousedown = function(){return false}
}
</script>
<form name=frm>
<input type=button name=btn value="Hide menubar" oclick='disableMenu()'/>
<input type=button name=btn value="Show menubar" oclick='enableMenu()'/>
</form>
</body>
</html>
--------------------------------------------------
Thanks
Ashish
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
For IE5 and above you can add this to your body tag to prevent the right-click:
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
<input type=button name=btn value="Hide menubar" oclick='disableMenu()'/>
<input type=button name=btn value="Show menubar" oclick='enableMenu()'/>
</form>
Quick question:
ummmm shouldn't the stuff in bold be onclick??
Reda Mokrane
Ranch Hand

Joined: Jul 25, 2001
Posts: 237
you are correct they should be but before your post Javaranch does not allow onclick to be posted.
[ January 10, 2002: Message edited by: Reda Mokrane ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Ah forgot about that..lol...and it says it above....duh...was not awake when I read that!
[ January 11, 2002: Message edited by: Al Ian ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Disable Right Click,View source and save as