Link to home
Start Free TrialLog in
Avatar of nhoj
nhoj

asked on

Disable view source

Hi

Using Delphi 5.0 Pro. Is it possible to disable the 'View source' option on the pop-up menu that appears when you right click on the TWebBrowser component. Disabling the the pop-up menu completely is acceptable. I have tried adding my own pop-up menu and setting the popupmenu property of the web browser component to use this pop up menu, but it did not work, the default menu still appeared.

Thanks

John
Avatar of Epsylon
Epsylon

You can protect your own pages in IE with:

<body oncontextmenu="return false" ...>
...
</body>
Add the following to you HTML

<script language="JavaScript">
<!--  
if (navigator.appName.indexOf("Internet Explorer") != -1)  
document.onmousedown = noSourceExplorer;  
function noSourceExplorer(){if (event.button == 2 | event.button == 3)  
{  
alert("your message here!");}
}  
//-->    
</script>

JL
jlislo, what if it should disable the menu for all pages on the internet?
Avatar of nhoj

ASKER

Epsylon's answer works just fine, and since this is a custom app using the Delphi web browser component I will accept this as an answer if Epsylon would like to post it as such.

Regards John
Epsylon,

Try add the javascript code to the document in run time. This is just a thought I don't have D5 at work, I have to try it at home tonight.
if you wish to disable the popup menu or use your own you can do it this:

procedure MessageLoop(var Msg:TMsg;var Handled:Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.MessageLoop(var Msg: TMsg; var Handled: Boolean);
var
 mouse:Tpoint;
begin
if msg.hwnd = webbrowser1.Handle then
  begin
   if (Msg.Message = WM_RBUTTONDOWN) or (Msg.Message = WM_RBUTTONUP)
   then begin
    handled:=True;
     getcursorpos(Mouse); //popup your own menu
    popupmenu1.popup(Mouse.x,Mouse.y);
   end
  else Handled := False; //not rbutton
 end
else
Handled := false; //not webbrowser msg
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := MessageLoop;
end;
It's not right.
You disable all popup menu from brower control
not only 'view source' option.
Right way is to implement IDocHostUIHandler,
and in IDocHostUIHandler:: ShowContextMenu
popup own menu.
nhoj, if you want to accept my answer you must reject jlislo's first...
Avatar of nhoj

ASKER

Epsylon's comment woorks fine and is simple to implement, the fact that the pop-up menu does not appear at all does not matter since there are other functions on this menu that W also wanted to disable e.g. "Print" as I have my own print function which will print over the page properly.

Thanks

Regards John
Thank you, John.
ASKER CERTIFIED SOLUTION
Avatar of Epsylon
Epsylon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial