|
|
 |
| Javascript General Javascript discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

April 6th, 2006, 10:16 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,518
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
disable right-click on FF and OP
Code:
// Prevent page from being right-clicked at any point
// for images, view source etc....
if (window.Event)
{
document.captureEvents(Event.MOUSEUP);
}
function nocontextmenu()
{
event.cancelBubble = true, event.returnValue = false;
return false;
}
function norightclick(e)
{
if (window.Event)
{
if (e.which == 2 || e.which == 3)
{
return false;
}
else if (event.button == 2 || event.button == 3)
{
event.cancelBubble = true, event.returnValue = false;
return false;
}
}
}
if (document.layers)
{
document.captureEvents(Event.MOUSEDOWN);
}
document.oncontextmenu = nocontextmenu;
document.onmousedown = norightclick;
document.onmouseup = norightclick;
This code works on IE6 (and 7), but does anyone have a version that will work on FF/OP?
Picco
www.crmpicco.co.uk
www.ie7.com
|

April 6th, 2006, 03:51 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,697
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Standards-following browsers accept the event object as the first argument to the event handling function.
To make this cross-browser, you handle the event like this:
Code:
function($e)
{
// If $e evaluates to false, assign it window.event.
($e = ($e || window.event));
}
If you want to cancel a right click, just do this
Code:
document.oncontextmenu = function($e)
{
if (window.event)
{
window.event.returnValue = false;
}
else
{
$e.preventDefault();
}
};
Opera does not support the "oncontextmenu" event.
HTH!
Regards,
Rich
--
[ http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
|

April 12th, 2006, 04:02 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,518
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks Richard, I read up on the Opera situation and it seems you can't disable right-click on Opera at all.
i wanted it just for effect, not to protect code or anything.
Cheers.
Picco
www.crmpicco.co.uk
www.ie7.com
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |