my dog learned polymorphism*
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
Author

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")
shiftPressed=(e.modifiers-0>3);
else
shiftPressed=event.shiftKey;

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

return true;
}

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

if (navigator.appName=="Netscape")
document.captureEvents(Event.MOUSEDOWN);
}

Thank s in advance
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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?

Eric
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
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

"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.

Thanks!
bear
JavaRanch Sheriff


[Asking smart questions] [Bear's FrontMan] [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='http://www.yahoo.com';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(window.open(location.href))" - 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: http://aspose.com/file-tools
 
subject: Disabling shift-click button