• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Disabling shift-click button

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic