How to call the OnChange event of “Select” ? (Delphi - WebBrowser)

戏子无情 提交于 2019-12-31 04:05:53

问题


I'm using Delphi and WebBrowser componenet to navigate a html page . the page have a Combobox . is there any way to call the OnChange event ?

The ComboBox is like this :

<select name="comboname" onchange="Some Javascript codes">

Also , i have used this code :

function TFrmMain.SetComboboxValue(WB: TEmbeddedWB;
  SelectName, ItemName: string): Boolean;
var
  iForms, iFormItems, iSelectItems: Word;
  FormItem: OleVariant;
begin
  Result := false;
  for iForms := 0 to WB.OleObject.Document.Forms.length - 1 do
  begin
    FormItem := WB.OleObject.Document.Forms.item(iForms);
    for iFormItems := 0 to FormItem.length - 1 do
    begin
      if (FormItem.item(iFormItems). type = 'select-one') and SameText
        (FormItem.item(iFormItems).Name, SelectName) then
      begin
        for iSelectItems := 0 to FormItem.item(iFormItems).Options.length - 1 do
        begin
          if SameText(FormItem.item(iFormItems).Options.item(iSelectItems)
              .Text, ItemName) then
          begin
            FormItem.item(iFormItems).SelectedIndex := iSelectItems;
            Result := true;
            Break;
          end;
        end;
      end;
    end;
  end;
end;

But it change the value only.


回答1:


to execute the onchange event you can use the execScript method

check this sample

uses
  MSHTML;

var
  Doc: IHTMLDocument2;      
  HTMLWindow: IHTMLWindow2;           
begin
  Doc := WebBrowser1.Document as IHTMLDocument2;
  if not Assigned(Doc) then
    Exit;
  HTMLWindow := Doc.parentWindow;
  if not Assigned(HTMLWindow) then
    Exit;

  HTMLWindow.execScript('yourfunctioname()', 'JavaScript'); 
end;

for more info check this excellent article

  • How to call JavaScript functions in a TWebBrowser from Delphi



回答2:


Inspired by the response. NET have been using the structures below:

FrameSet Document Elements Item Name Value Change ;
EWB.OleObject.Document.Frames.Item('mainFrame').Document.Forms.Item('invoiceForm').Elements.Item('inputname').Value:= '123456';

or

FrameSet Document Elements Items Lenth;

EWB.OleObject.Document.Forms.Item('invoiceForm').Elements.Length;


来源:https://stackoverflow.com/questions/3724822/how-to-call-the-onchange-event-of-select-delphi-webbrowser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!