Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Disabling shift-click button

 
Surya Kant
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
Yuriy Fuksenko
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic