Delphi - 在网络浏览器中运行 javascript
嗨,
我正在delphi中将网页加载到Twebrowser中,该网页有一个带有下拉菜单的表单。我可以让我的程序像下拉菜单一样选择项目ID,但是选择选项有一个onchange事件,我如何在delphi中触发onchange事件而不使用execScript('yourfunctioname()', 'JavaScript') ;
这是带有 onChnage 事件的选择,
<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>
我通过执行以下操作使其工作:
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;
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="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>
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这将起作用:
并且这与后期绑定有关
This will work:
and this with late binding