不点击一个脚本元素,如何获取脚本指向的url(300)

  • 主题发起人 happymanfreeman
  • 开始时间
H

happymanfreeman

Unregistered / Unconfirmed
GUEST, unregistred user!
各位高手; 大家知道, 在web上点击一个脚本元素, web会立即转向新的页面, 现在不点击此脚本元素, 如何通过DOM分析获取脚本指向的url ? 以下代码不行, 报告"接口不支持"的错误, 请大家指出错在哪里 procedure TForm1.Button1Click(Sender: TObject);var doc2:IHTMLDocument3; el:IHTMLElement; DoC: IHTMLDocument2; ActiveElement: IHTMLScriptElement; HTMLElementCollection:IHTMLElementCollection;begin doc2 := WebBrowser1.Document as IHTMLDocument3; //获取页面的文档对象 el := doc2.getElementById('check2()'); DoC := el as IHTMLDocument2; if Doc <> nil then begin HTMLElementCollection:= Doc.scripts ; ActiveElement:= HTMLElementCollection.item(0,0) as IHTMLScriptElement; if ActiveElement<>nil then Memo3.Lines.Add(ActiveElement.src ); end;end; ( 网页上确实有id check2() ) 但是如果不这样获取, 先取得整个网页的所有Script集合, 到底如何确定哪一个Script才是 目标Script ?? 比如已知点击引起脚本执行的网页元素的id等 , 比如以下代码 var DoC: IHTMLDocument2; ActiveElement: IHTMLScriptElement; HTMLElementCollection:IHTMLElementCollection; s: string;begin Doc := EmbeddedWB1.Document as IHTMLDocument2; if Doc <> nil then begin HTMLElementCollection:= Doc.scripts; ActiveElement:= HTMLElementCollection.item(0,0) as IHTMLScriptElement; // 可以通过循环和 HTMLElementCollection.item 方法枚举获得整个网页的各个IHTMLScriptElement, 但是, 到底如何确定哪一个IHTMLScriptElement才是目标Script ?? 已知点击引起脚本执行的网页元素的id等 ...... end;end;以上请教高手, 谢谢 !!!
 

Similar threads

I
回复
0
查看
530
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
560
import
I
顶部