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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable Right Click on Web Page:

Status
Not open for further replies.

nospace52

Technical User
Jan 28, 2003
27
0
0
US
I have a JavaScript that will disable the Right Click on a web page:
============================================================
<title>Out Today</title>
</head>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!-- start hide

document.onmousedown = click;

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

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

// end hide -->
</SCRIPT>

<body bgcolor=&quot;#C0C0C0&quot;>
=======================================================
The problem I'm having is that when a user Right Clicks on the page the Title of the web page changes to the URL of the web page. How or what could be added to prevent this or make the Title reflect something like &quot;XX&quot; ?

Thanks

< I want to work in Theory - everything and everybody works in Theory !!>
 
It does that because of your document.write(&quot;&quot;) statement. I'm not sure what that hopes to achieve.

BTW: Do you realise that most keyboards now come with a context menu key... meaning that overriding the mouse click won't prevent the context menu from showing?

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]
 
Nospace52,

Did you try to run you source code in NS 6 or 7?

 

Check out this thread: thread216-806533

It has an idea about stopping the context menu, even if invoked with the keyboard.

I haven't tried it, however, so no idea if it works in all browsers or not.

Dan
 
For IE only it's much better to use oncontextmenu event (Shift-F10, right mouse click).
 
I still don't see why you would want to annoy your users in such a fashion.

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

AU.gif
Check out Tek-Tips Australia New Zealand forum1155
NZ.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top