Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 6th, 2006, 09:16 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default 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
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
Reply With Quote
  #2 (permalink)  
Old April 6th, 2006, 02:51 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

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
Reply With Quote
  #3 (permalink)  
Old April 12th, 2006, 03:02 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
disable browser right click?? danielnixon HTML Code Clinic 1 May 19th, 2008 12:11 PM
How to disable Right-click to Save Picture As.... bekim HTML Code Clinic 11 January 9th, 2005 02:09 AM
Disable Right-click for Save Image As... bekim Javascript How-To 5 January 7th, 2005 09:03 PM
Flash object: disable right click on it karib Flash (all versions) 4 April 25th, 2004 01:08 AM
disable right click for onMouseUp dhaywirex Classic ASP Basics 2 March 4th, 2004 05:22 AM



All times are GMT -4. The time now is 08:36 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.