Delphi - run javascript in a webbrowser [duplicate]
Possible Duplicate:
How to call the OnChange event of “Select” ? (Delphi - WebBrowser)
Hi,
I'm loading a web page into a Twebrowser in delphi, the webpage has a form with a drop down. I can get my program to select the item id like in the drop down menu but the select option has a onchange event how can i fire the onchange event in delphi without using execScript('yourfunctioname()', 'JavaScript');
heres the select with the onChnage event
<select align="left" id="carr开发者_运维百科ierNameDropDown_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>
I got it to work by doing:
if EmbeddedWB1.Document <> nil then begin
if EmbeddedWB1.Document.QueryInterface(IHTMLDocument3,docb) = S_OK then begin
elb := docb.getElementById('carrierNameDropDown_UNSHIPPEDITEMS');
if elb <> nil then begin
(elb as IHTMLSelectElement).value := 'Parcelforce';
OleVariant (elb as IHTMLElement). FireEvent ('onchange');
end;
This will work:
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;
and this with late binding
procedure TBrowserPageIE.Test;
var
doc : IHTMLDocument3;
el : OleVariant;
v : OleVariant;
begin
if FBrowser.Document <> nil then begin
if FBrowser.Document.QueryInterface(IHTMLDocument3,doc) = S_OK then begin
el := doc.getElementById('carrierNameDropDown_UNSHIPPEDITEMS');
el.value := 'UPS';
el.FireEvent('onchange', v);
end;
end;
end;
精彩评论