Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restricting the right-click context menu

Status
Not open for further replies.

AndyGroom

Programmer
May 23, 2001
972
GB
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
 
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).

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

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top