stuayre
asked on
How do I fire an onChnage even in a twebbrowser - Delphi
Hi,
I'm loading a webpage into a twebbrowser in delphi
the webpage contains a dropdown menu, i can select the menu item i want but it wont fire the OnChange event.
I've tried to use the HTMLWindow.execScript('you rfunctiona me()', 'JavaScript'); method
but it always throws back errors (delphi could not complete the operation due to error 80020101) I think it might be an AJAX issue.
I was trying to get around it by using the OleVariant(yourIHTMLElemen t).FireEve nt('onchan ge') ; method but im not sure how to use it, can anyone provide an example?
the only other way would be to simulate a mouse click on the dropdown?
here's the dropdown im trying to change:
many thanks
Stu
I'm loading a webpage into a twebbrowser in delphi
the webpage contains a dropdown menu, i can select the menu item i want but it wont fire the OnChange event.
I've tried to use the HTMLWindow.execScript('you
but it always throws back errors (delphi could not complete the operation due to error 80020101) I think it might be an AJAX issue.
I was trying to get around it by using the OleVariant(yourIHTMLElemen
the only other way would be to simulate a mouse click on the dropdown?
here's the dropdown im trying to change:
many thanks
Stu
<select align="left" id="carrierNameDropDown_UNSHIPPEDITEMS" onChange="MYO.ES.OtherCarrierToggle (this, 'UNSHIPPEDITEMS' )">
<option value="0" selected="1" >Select</option>
<option value="Chronopost" >Chronopost</option>
<option value="City Link" >City Link</option>
<option value="DHL" >DHL</option>
<option value="DPD" >DPD</option>
<option value="Deutsche Post" >Deutsche Post</option>
<option value="Fastway" >Fastway</option>
<option value="FedEx" >FedEx</option>
<option value="GLS" >GLS</option>
<option value="GO!" >GO!</option>
<option value="Hermes Logistik Gruppe" >Hermes Logistik Gruppe</option>
<option value="La Poste" >La Poste</option>
<option value="Parcelforce" >Parcelforce</option>
<option value="Parcelnet" >Parcelnet</option>
<option value="Poste Italiane" >Poste Italiane</option>
<option value="Royal Mail" >Royal Mail</option>
<option value="SDA" >SDA</option>
<option value="Smartmail" >Smartmail</option>
<option value="TNT" >TNT</option>
<option value="Target" >Target</option>
<option value="UPS" >UPS</option>
<option value="Yodel" >Yodel</option>
<option value="Other">
Specify carrier:
</option>
</select>
hi
some solutions for you
try it
by
kumaresan
some solutions for you
try it
by
kumaresan
uses
MSHTML;
procedure TBrowserPageIE.Test;
var
doc : IHTMLDocument3;
el : IHTMLElement;
v : OleVariant;
begin
if FBrowser.Document <> nil then begin
if FBrowser.Document.QueryInterface(IHTMLDocument3,doc) = S_OK then begin
el := doc.getElementById('carrierNameDropDown_UNSHIPPEDITEMS');
if el <> nil then begin
(el as IHTMLSelectElement).value := 'UPS';
(el as IHTMLElement3).FireEvent('onchange', v);
end;
end;
end;
end;
hi
look this, it may be help ful to you
procedure TForm1.Button3Click(Sender : TObject);
var Doc: IHTMLDocument2;
HTMLWindow: IHTMLWindow2; // parent window of current HTML document
begin
with form1 do
begin
Doc := WebBrowser1.Document as IHTMLDocument2;
if not Assigned(Doc) then Exit;
HTMLWindow := Doc.parentWindow;
if not Assigned(HTMLWindow) then Exit;
HTMLWindow.execScript('_my oES_OtherC arrierTogg le(changec olour)', 'Javascript');
end;
end;
Unit1.dfm
Unit1.pas
Article21.dpr
FmDemo.dfm
FmDemo.pas
Test.html
look this, it may be help ful to you
procedure TForm1.Button3Click(Sender
var Doc: IHTMLDocument2;
HTMLWindow: IHTMLWindow2; // parent window of current HTML document
begin
with form1 do
begin
Doc := WebBrowser1.Document as IHTMLDocument2;
if not Assigned(Doc) then Exit;
HTMLWindow := Doc.parentWindow;
if not Assigned(HTMLWindow) then Exit;
HTMLWindow.execScript('_my
end;
end;
Unit1.dfm
Unit1.pas
Article21.dpr
FmDemo.dfm
FmDemo.pas
Test.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
this one works
https://www.experts-exchange.com/questions/24033014/call-an-onchange-event-in-webbrowser.html
https://www.experts-exchange.com/questions/23495082/TWebBrowser-Event-Capturing.html
http://stackoverflow.com/questions/3724822/how-to-call-the-onchange-event-of-select-delphi-webbrowser