gpt4 book ai didi

c# - IE 9 BHO 插件。加载外部 JS 文件时出现错误 SCRIPT1014

转载 作者:行者123 更新时间:2023-11-30 18:37:48 25 4
gpt4 key购买 nike

我正在尝试使用 .Net 和 BHO 创建简单的 Internet Explorer 9 插件,以在页面上加载外部 js 文件并执行它。

我创建了 ieInstance_DownloadComplete(我也试过 ieInstance_DocumentComplete,但情况更糟)事件处理程序:

InternetExplorer explorer = this.ieInstance;
var document = explorer.Document as IHTMLDocument2;
document.parentWindow.execScript(
@"
if (document.getElementById('KCScript') == null)
{
var fileref=document.createElement('script');
fileref.setAttribute('id', 'KCScript');
fileref.setAttribute('type','text/javascript');
fileref.setAttribute('charset', 'UTF-8')
fileref.setAttribute('src', 'C:/test.js');
fileref.onload = function () { eee(); };
if (typeof fileref!='undefined')
document.getElementsByTagName('head')[0].appendChild(fileref);}","JavaScript");
}

加载页面后,我可以在 IE 开发人员工具中看到我的 test.js 附加到页面。但是函数 eee() 没有引发,我有一个错误:“SCRIPT1014:无效字符test.js,第 1 行,字符 1"

测试.js:

function eee()
{
alert('ttt!');
};

test.js是UTF-8的,所以没有读取问题..还有其他的

怎么了?有任何想法吗?提前致谢!

最佳答案

  1. 尝试用“UTF-8 without BOM”编码重新保存JS
  2. 尝试将JS作为http://example.com/test.js放到远程服务器上

关于c# - IE 9 BHO 插件。加载外部 JS 文件时出现错误 SCRIPT1014,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12172796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com