Hello friends,
I want to bulid a page that is restricted with right click. That means, any where on page right click is restricted. How to do that?
If possible help me with the code?
9 7391
Use this friend this will work for u
<html><body oncontextmenu="return false;" >
Will you please excuse me that
can you please give me full code with an example please my friend , i am poor at javascript.
Ok friend you ahve to do nothing just write in the body tag oncontextmenu="return false;". If you will return true then it will enable the right click.
like this for example .This is full code .You ac save this with .html extension and see that right click is disabled
[HTML]<html><body oncontextmenu="return false;" >
<td><span>Action</span></td>
<td><select id="combo1" name="combo1" size="1" class="optional" >
<option value="condition 1">Proceed</option>
<option value="condition 2">Reject</option></select></td>
<td><span>No Action</span></td>
<td><select id="combo2" name="combo2" size="1" class="optional" >
<option value="condition 1">Proceed</option>
<option value="condition 2">Reject</option></select></td>
<td><input type="file" id ="attachment"/></td>
</body></html>[/HTML]
Hi friend,
sorry it is allowing the right click on the page. It displays two select boxes and a file box. But it allowing the right click on the page. I want disallow right click on total page.
The first question to ask yourself is why you even need this script. If it's to protect the source code or images, forget it. It's annoying and the users who do want access can easily work around your little script. For images, watermark them instead.
If you must, you can use the right click detection script described here.
Please can you please let me know about the Internet Explorer or browser's information like
version and name because it is working fine in my environment i.e with IE 6thversion.
In order to deal whith right click you must overide the context menu - <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-
"http://www.w3.org/tr/xhtml1/DTD/xhtml1-transitional.dtd">
-
<!--
-
Example File From "JavaScript and DHTML Cookbook"
-
Published by O'Reilly & Associates
-
Copyright 2003 Danny Goodman
-
-->
-
<html>
-
<head>
-
<title>Recipe 10.7</title>
-
<style rel="stylesheet" id="mainStyle" type="text/css">
-
html {background-color:#cccccc}
-
body {background-color:#eeeeee; font-family:Tahoma,Arial,Helvetica,sans-serif; font-size:12px;
-
margin-left:15%; margin-right:15%; border:3px groove darkred; padding:15px}
-
h1 {text-align:right; font-size:1.5em; font-weight:bold}
-
h2 {text-align:left; font-size:1.1em; font-weight:bold; text-decoration:underline}
-
.buttons {margin-top:10px}
-
-
-
</style>
-
<style type="text/css">
-
.contextMenus {position:absolute; background-color:#cfcfcf;
-
border-style:solid; border-width:1px;
-
border-color:#EFEFEF #505050 #505050 #EFEFEF;
-
visibility:hidden}
-
.menuItem {cursor:pointer; font-size:9pt;
-
font-family:Arial, Helvetica, sans-serif;
-
padding-left:5px; color:black;
-
background-color:transparent;
-
text-decoration:none}
-
.menuItemOn {cursor:pointer; font-size:9pt;
-
font-family:Arial, Helvetica, sans-serif;
-
padding-left:5px; color:red;
-
background-color:yellow;
-
text-decoration:underline}
-
.contextEntry {font-weight:bold; color:darkred; cursor:pointer}
-
</style>
-
-
<script type="text/javascript">
-
// context menu data objects
-
var cMenu = new Object();
-
cMenu["lookup1"] = {menuID:"contextMenu1", hrefs:["http://www.m-w.com/cgi-bin/dictionary?book=Dictionary&va=sesquipedalian","http://www.m-w.com/cgi-bin/dictionary?book=Thesaurus&va=sesquipedalian"]};
-
cMenu["lookup2"] = {menuID:"contextMenu2", hrefs:["http://www.wyomingtourism.org/","http://www.pbs.org/weta/thewest/places/states/wyoming/","http://cnn.looksmart.com/r_search?l&izch&pin=020821x36b42f8a561537f36a1&qc=&col=cnni&qm=0&st=1&nh=10&rf=1&venue=all&keyword=&qp=&search=0&key=wyoming","http://google.com","http://search.yahoo.com"]};
-
-
// position and display context menu
-
function showContextMenu(evt) {
-
// hide any existing menu just in case
-
hideContextMenus();
-
evt = (evt) ? evt : ((event) ? event : null);
-
if (evt) {
-
var elem = (evt.target) ? evt.target : evt.srcElement;
-
if (elem.nodeType == 3) {
-
elem = elem.parentNode;
-
}
-
if (elem.className == "contextEntry") {
-
var menu = document.getElementById(cMenu[elem.id].menuID);
-
// turn on IE mouse capture
-
if (menu.setCapture) {
-
menu.setCapture();
-
}
-
// position menu at mouse event location
-
var left, top;
-
if (evt.pageX) {
-
left = evt.pageX;
-
top = evt.pageY;
-
} else if (evt.offsetX || evt.offsetY) {
-
left = evt.offsetX;
-
top = evt.offsetY;
-
} else if (evt.clientX) {
-
left = evt.clientX;
-
top = evt.clientY;
-
}
-
menu.style.left = left + "px";
-
menu.style.top = top + "px";
-
menu.style.visibility = "visible";
-
if (evt.preventDefault) {
-
evt.preventDefault();
-
}
-
evt.returnValue = false;
-
}
-
}
-
}
-
-
// retrieve URL from cMenu object related to chosen item
-
function getHref(tdElem) {
-
var div = tdElem.parentNode.parentNode.parentNode.parentNode;
-
var index = tdElem.parentNode.rowIndex;
-
for (var i in cMenu) {
-
if (cMenu[i].menuID == div.id) {
-
return cMenu[i].hrefs[index];
-
}
-
}
-
return "";
-
}
-
-
// navigate to chosen menu item
-
function execMenu(evt) {
-
evt = (evt) ? evt : ((event) ? event : null);
-
if (evt) {
-
var elem = (evt.target) ? evt.target : evt.srcElement;
-
if (elem.nodeType == 3) {
-
elem = elem.parentNode;
-
}
-
if (elem.className == "menuItemOn") {
-
location.href = getHref(elem);
-
}
-
hideContextMenus();
-
}
-
}
-
-
// hide all context menus
-
function hideContextMenus() {
-
if (document.releaseCapture) {
-
// turn off IE mouse event capture
-
document.releaseCapture();
-
}
-
for (var i in cMenu) {
-
var div = document.getElementById(cMenu[i].menuID)
-
div.style.visibility = "hidden";
-
}
-
}
-
-
// rollover highlights of context menu items
-
function toggleHighlight(evt) {
-
evt = (evt) ? evt : ((event) ? event : null);
-
if (evt) {
-
var elem = (evt.target) ? evt.target : evt.srcElement;
-
if (elem.nodeType == 3) {
-
elem = elem.parentNode;
-
}
-
if (elem.className.indexOf("menuItem") != -1) {
-
elem.className = (evt.type == "mouseover") ? "menuItemOn" : "menuItem";
-
}
-
}
-
}
-
-
// set tooltips for menu-capable and lesser browsers
-
function setContextTitles() {
-
var cMenuReady = (document.body.addEventListener || typeof document.oncontextmenu != "undefined")
-
var spans = document.body.getElementsByTagName("span");
-
for (var i = 0; i < spans.length; i++) {
-
if (spans[i].className == "contextEntry") {
-
if (cMenuReady) {
-
var menuAction = (navigator.userAgent.indexOf("Mac") != -1) ? "Click and hold " : "Right click ";
-
spans[i].title = menuAction + "to view relevant links"
-
} else {
-
spans[i].title = "Relevant links available with other browsers (IE5+/Windows, Netscape 6+)."
-
spans[i].style.cursor = "default";
-
}
-
}
-
}
-
}
-
-
// bind events and initialize tooltips
-
function initContextMenus() {
-
if (document.body.addEventListener) {
-
// W3C DOM event model
-
document.body.addEventListener("contextmenu", showContextMenu, true);
-
document.body.addEventListener("click", hideContextMenus, true);
-
} else {
-
// IE event model
-
document.body.oncontextmenu = showContextMenu;
-
}
-
// set intelligent tooltips
-
setContextTitles();
-
}
-
-
-
</script>
-
</head>
-
<body onload="initContextMenus()">
-
<h1>Custom Contextual Menu</h1>
-
<hr />
-
-
<p>This sentence has at least one <span id="lookup1" class="contextEntry">sesquipedalian</span> word
-
and mention of the state of <span id="lookup2" class="contextEntry">Wyoming</span>, both of which could have additional lookups.</p>
-
-
<div id="contextMenu1" class="contextMenus" onclick="hideContextMenus()" onmouseup="execMenu(event)" onmouseover="toggleHighlight(event)" onmouseout="toggleHighlight(event)">
-
<table><tbody>
-
<tr><td class="menuItem">Merriam-Webster Dictionary</td></tr>
-
<tr><td class="menuItem">Merriam-Webster Thesaurus</td></tr>
-
</tbody></table>
-
</div>
-
-
<div id="contextMenu2" class="contextMenus" onclick="hideContextMenus()" onmouseup="execMenu(event)" onmouseover="toggleHighlight(event)" onmouseout="toggleHighlight(event)">
-
<table><tbody>
-
<tr><td class="menuItem">Wyoming Tourist Info</td></tr>
-
<tr><td class="menuItem">State Map</td></tr>
-
<tr><td class="menuItem">cnn.com</td></tr>
-
<tr><td class="menuItem">Google</td></tr>
-
<tr><td class="menuItem">Yahoo Search</td></tr>
-
</tbody></table>
-
</div>
-
-
</body>
-
</html>
-
Online Example for Custom Contextual Menu(content sensitive)
Hai,
My operating system is ubuntu and i am using mozilla firefox 1.5.0.12eol. i don't have internet explorer.
As I asked earlier, why do you want to disable right click?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: George Hester |
last post by:
In a page I have when the user left-clicks the page a Input box for a form gets the focus. But if the user right-clicks the page the Input box is not getting the focus. I'd like the Input box to...
|
by: cmelnick |
last post by:
I need to determine whether the user used the right or left mouse
button to click an element on a form. AFAIK, there is no way to
determine this from the Click (or DoubleClick) event. I currently...
|
by: mitsura |
last post by:
Hi,
I have included a small listing. The test program opens a panel and
show a bitmap.
What I want is to when the mouse is over the bitmap panel, I want to
trap the left mouse click.
The...
|
by: paradox |
last post by:
How can I go about having a TreeNode selected when I right click? I
tried using the Click event, but the event does not pass in the node
that was clicked.
Currently you have to left click a node...
|
by: Dino M. Buljubasic |
last post by:
I have a list view with couple of items in it.
When I left click on an item, a form opens displaying that item's
properties. So that works fine.
However, accidentally I found out that when I...
|
by: Terry Olsen |
last post by:
How can I catch a right-click on a DropDownMenuItem?
|
by: Hardik Shah |
last post by:
Hi,
I want to create menu , when my user right click from combo box's list item.
I use Contextmenu property of combobox and assign menu for it, but it only
effected when combobox's list item not...
|
by: Pucca |
last post by:
How can I tell a mouse right clicks over a listview item that's in a
container panel. I only want to display a popup menu if the user right click
the mouse over an item on the Listview. I don't...
|
by: the_grove_man |
last post by:
How do I invoke a "Right-Click" Programmtically?
John
|
by: Shocky |
last post by:
Hi there,
I am trying to detect whether my IE6 users have pressed both right and
left mouse buttons simultaneously in my Javascript code, by using:
if(event.button==3) {alert("Both right and...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |