×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Restricting the right-click context menu

Restricting the right-click context menu

Restricting the right-click context menu

(OP)
I'm using a WebBrowser control within a VB application to display HTML documents, and I know I can disable the context menu by writing

CODE

oncontextmenu='return false'

into the Body tag of each page.

However, this also means that users can no longer highlight an area of text and right-click to access the more text-specific options such as Copy, Select All, Print etc, which I would like them to be able to access since it's a Windows convention.

Is it possible to disable the main context menu while still allowing the user to access the text-specific context menu?

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments

RE: Restricting the right-click context menu


I'd say you'd have to do some clever customisation within VB, rather than in the client-side if you want to still provide access to certain features.

Having said that, you might be able to write your own right-click menu which has the features you want (especially if you're only using an IE control).

Quote:

which I would like them to be able to access since it's a Windows convention.

Right-clicking to copy/paste isn't necessarily a 'Windows convention' - each user will have their own preference. For example, I'll always use the keyboard and never the right-click menu, and some people will use the menu bar in their application.

Hope this helps,
Dan

 

Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page @ Code Couch
http://www.codecouch.com/dan/


 

RE: Restricting the right-click context menu

(OP)
That's true, I also use the keyboard to copy because it's quicker. But, I'm dealing with clients who aren't that savvy, and I guess there's also a comfort level factor in being able to right-click and do something.

I don't think there's an easy solution to this. I know I could change the popup menu options in the Registry but that would also affect normal IE usage outside of my app.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments

RE: Restricting the right-click context menu

(OP)
I'm 90% of the way to getting what I want.

In the code below when the user right-clicks on empty space, no context menu appears. If they highlight any text and right-click, they get the Cut / Copy / Paste etc menu.

To make this code perfect I just need the last 10%, because if the user then goes back and right-clicks on empty space they get the main context menu popping up - which is what I want to hide.

CODE

<HTML>

<HEAD>
<SCRIPT LANGUAGE="JavaScript">
var text = "";
function getActiveText(e) {

text = (document.all) ? document.selection.createRange().text : document.getSelection();

if (text != '') document.body.oncontextmenu='return true';

}

document.onmouseup = getActiveText;
if (!document.all) document.captureEvents(Event.MOUSEUP);
</script>
</HEAD>

<BODY oncontextmenu='return false'>
<P>This is a big test!</P>
</BODY>
</HTML>
 

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close