Solved

onmouseover JavaScript Functions

Posted on 2011-09-30
2
614 Views
Last Modified: 2012-05-12
Hi i want to run some onmousedown js function, but how can i run this function without onmousedown event, in twebbrowser

Can you suggest me a proper function, please? thanks..
0
Comment
Question by:gsamuk
2 Comments
 
LVL 3

Accepted Solution

by:
Morphor earned 500 total points
ID: 36891138
WebBrowser1.Perform(WM_LButtonDown,0,0);
//    or
WebBrowser1.Perform(WM_RButtonDown,0,0);

Open in new window


Second option (change foo() to your function):
uses
  MSHTML;

procedure TForm1.CallFoo(S: string; I: Integer);
  { Calls JavaScript foo() function }
var
  Doc: IHTMLDocument2;      // current HTML document
  HTMLWindow: IHTMLWindow2; // parent window of current HTML document
  JSFn: string;             // stores JavaScipt function call
begin
  // Get reference to current document
  Doc := WebBrowser1.Document as IHTMLDocument2;
  if not Assigned(Doc) then
    Exit;
  // Get parent window of current document
  HTMLWindow := Doc.parentWindow;
  if not Assigned(HTMLWindow) then
    Exit;
  // Run JavaScript
  try
    JSFn := Format('foo("%s",%d)', [S, I]);  // build function call
    HTMLWindow.execScript(JSFn, 'JavaScript'); // execute function
  except
    // handle exception in case JavaScript fails to run
  end;
end;

Open in new window


Source: http://www.delphidabbler.com/articles?article=21
0
 
LVL 9

Expert Comment

by:Mahdi78
ID: 36892064
You can disable executing javascript by click, so you have to use OnBeforeNavigate2 even in WebBrowser by this way


procedure TForm1.WebBrowser1BeforeNavigate2(ASender: TObject;
  const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
  Headers: OleVariant; var Cancel: WordBool);
var LastURL: string;
begin
cancel := pos('javascript', URL) > 0;
end;

Open in new window

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now