File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Disabling shift-click button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Disabling shift-click button" Watch "Disabling shift-click button" New topic

Disabling shift-click button

Surya Kant
Ranch Hand

Joined: Mar 29, 2005
Posts: 104
I want to disable right click in my application.Here are my requirements.

1. I don't what to turn off shift click for the page. I want to turn it off for specific links.
2. I want shift-click to be replaced with a regular click. Meaning, when the user shift-clicks the link they will be taken to the "HREF" within the current browser window and NOT open up a new window.

I did find a script that does something close to what I want, but it fails to meet all of the criteria above... I'll list it below so someone doesn't waste their time providing it as a solution....

function mouseDown(e)
var shiftPressed=0;
if (parseInt(navigator.appVersion)>3)
if (navigator.appName=="Netscape")

if (shiftPressed)
alert ('Shift-click is disabled.')
return false;

return true;

if (parseInt(navigator.appVersion)>3)
document.onmousedown = mouseDown;

if (navigator.appName=="Netscape")

Thank s in advance
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
With my browser I can trun off all of your attempts to do this so it is rather worthless effort. When problems does it cause when someone opens up the window in another browser?

Surya Kant
Ranch Hand

Joined: Mar 29, 2005
Posts: 104
Hi eric,
With my code i can disbale shift-click .But when i click on any link it wil open in new window.i want to avoid that.
Hope u understood what problem i am facing
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63844

"surya mm",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

JavaRanch Sheriff

[Asking smart questions] [About Bear] [Books by Bear]
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
the sipliest way for you would be not using the href but to use onclick event on a links you need to restrict from opening - something like

<a href="javascript:#" onclick="location.href='';return false;">test</a>

But again, if I really want to open something in a new window, you cannot do anything with any type of javascript.
Try it yourself, open your page, type in a browser address bar "javascript:void(" - and you got a new window. I actually do something like that when I want to play with popups that peaple often open without address bar.
I agree. Here's the link:
subject: Disabling shift-click button
It's not a secret anymore!