【问题标题】:IE 9 BHO addon. Error SCRIPT1014 with loading external JS-fileIE 9 BHO 插件。加载外部 JS 文件时出现错误 SCRIPT1014
【发布时间】:2012-08-29 07:24:13
【问题描述】:

我正在尝试使用 .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"

test.js:

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

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

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

【问题讨论】:

    标签: c# javascript internet-explorer-9 bho add-on


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

    【讨论】:

      猜你喜欢
      • 2015-05-17
      • 2020-06-21
      • 2012-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-04
      • 2011-09-07
      • 1970-01-01
      相关资源
      最近更新 更多