This question was originally on the Browser forum but it has evolved into a Javascript question. Here's a summary of it:
I'm using a WebBrowser control within a VB application to display HTML documents, and I want to disable the Context Menu when the user right-clicks unless they have highlighted some text, in which case I want the context menu to appear.
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 a bit of help, 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.
- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
I'm using a WebBrowser control within a VB application to display HTML documents, and I want to disable the Context Menu when the user right-clicks unless they have highlighted some text, in which case I want the context menu to appear.
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 a bit of help, 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