Disabling right click on web browser control

  • Thread starter Thread starter Robert
  • Start date Start date
You can do it with JavaScript - here's a bit of JavaScript for how we did it...

<script language="JavaScript">
var ErrMsg = "Sorry! Right Click is disabled. Please use your browser menu options.";
function disableRightClick(btnClick)
{
if (navigator.appName == "Netscape" && btnClick.which == 3) // check for netscape and right click
{
alert(ErrMsg);
return false;
}
else if (navigator.appName =="Microsoft Internet Explorer" && event.button == 2) // for IE and Right Click
{
alert(ErrMsg);
return false;
}
}
document.onmousedown = disableRightClick;
</script>

This code also takes NetScape browsers into account.

Coleen
 
I cannot modify the HTML itself. I have created a small browser application
but I cannot have the right-click menu show up. Can I define my own and then
disable it? Will that override the default one the control has?

You can do it with JavaScript - here's a bit of JavaScript for how we did
it...

<script language="JavaScript">
var ErrMsg = "Sorry! Right Click is disabled. Please use your browser
menu options.";
function disableRightClick(btnClick)
{
if (navigator.appName == "Netscape" && btnClick.which == 3) // check for
netscape and right click
{
alert(ErrMsg);
return false;
}
else if (navigator.appName =="Microsoft Internet Explorer" && event.button
== 2) // for IE and Right Click
{
alert(ErrMsg);
return false;
}
}
document.onmousedown = disableRightClick;
</script>

This code also takes NetScape browsers into account.

Coleen
 
* "Robert said:
Can I programmatically disable the right click context menu?

\\\
<body onContextMenu="return false">
///

in your HTML file. Maybe this can be done using the DOM too.
 
Sorry, I don't know of any way to do this except through the JavaScript. Is
there a reason you can't modify the HTML?
 
Hi Robert

Implement the IDocHostUIHandler interface and in the ShowContextMenu
function return an HRESULT of S_OK. This will prevent the context menu from
being displayed.

You can inform the WebBrowser control that you have implemented the
IDocHostUIHandler interface by getting an ICustomDoc interface from the
document, and calling SetUIHandler method with a reference to your class
that implements the interface.

HTH

Charles
 
Hello Charles,
Hi Robert

Implement the IDocHostUIHandler interface and in the >ShowContextMenu
function return an HRESULT of S_OK. This will prevent the >context menu from
being displayed.

You can inform the WebBrowser control that you have >implemented the
IDocHostUIHandler interface by getting an ICustomDoc >interface from the
document, and calling SetUIHandler method with a >reference to your class
that implements the interface.

HTH

Charles

Do you know of a way / any documentation on using the IDocHostUIHandler
from VB6? I would like to pass user click events from the an HTML page
in the WebBroswer Control to my hosting VB app. Is this possible?


Cheers,
Nicolas
http://www20.brinkster.com/intefacesa/

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Hi Nicholas

Unfortunately I haven't used the WebBrowser control in VB6, so I am probably
not the best person to ask. You could try one of the dedicated VB
newsgroups: microsoft.public.vb.*etc*.

Perhaps someone else here can suggest a more specific group.

Charles
 
Back
Top