我用IHtmlDocument2(WB1.Document).write写入HTML后可以正常显示,但是里边的脚本却不执行,也不报错,没有任何提示,什么原因??
procedure TForm1.insertHTML(htmlStr: WideString; act: Integer);
var
tv: Variant;
begin
if act=0 then
begin
tv := VarArrayCreate([0, 0], varVariant);
tv[0] := htmlStr;
IHtmlDocument2(WB1.Document).write(PSafeArray(TVarData(tv).VArray));
end
else if act=1 then
IHtmlDocument2(WB1.Document).Body.innerHtml := IHtmlDocument2(WB1.Document).Body.innerHtml + htmlStr
else
IHtmlDocument2(WB1.Document).Body.innerHtml := '';
end;完整代码如上,第一步先用write写入HTML,第二步用innerHtml写入具体表格,但是第二步里调用第一步写入的脚本时却没有任何反应....
procedure TForm1.insertHTML(htmlStr: WideString; act: Integer);
var
tv: Variant;
begin
if act=0 then
begin
tv := VarArrayCreate([0, 0], varVariant);
tv[0] := htmlStr;
IHtmlDocument2(WB1.Document).write(PSafeArray(TVarData(tv).VArray));
end
else if act=1 then
IHtmlDocument2(WB1.Document).Body.innerHtml := IHtmlDocument2(WB1.Document).Body.innerHtml + htmlStr
else
IHtmlDocument2(WB1.Document).Body.innerHtml := '';
end;完整代码如上,第一步先用write写入HTML,第二步用innerHtml写入具体表格,但是第二步里调用第一步写入的脚本时却没有任何反应....
IHtmlWindow2((WebBrowser1.Document as IHTMLDocument2).parentWindow).execScript(
'alert(document.body.innerHTML)', 'JavaScript');//怎么添加还在搜索中~~
When using the insertAdjacentHTML method to insert script, you must include the DEFER attribute in the script element. //看来不能直接加在body里,你可以将脚本加在div等元素里~~