简体   繁体   English

IE 9 BHO插件。 加载外部JS文件时出错SCRIPT1014

[英]IE 9 BHO addon. Error SCRIPT1014 with loading external JS-file

I'm trying to create simple Internet Explorer 9 addon using .Net and BHO to load external js-file on page and execute it. 我正在尝试使用.Net和BHO创建简单的Internet Explorer 9插件,以在页面上加载外部js文件并执行它。

I created ieInstance_DownloadComplete (I also tried ieInstance_DocumentComplete, but things were worse) event handler: 我创建了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");
  }

When page is loaded I can see my test.js attached to page in IE Developer Tools. 当页面加载时,我可以在IE Developer Tools中看到我的test.js附加到页面。 But function eee() does not raise and i have an error: "SCRIPT1014: Invalid character test.js, line 1, character 1" 但函数eee()不会引发错误:“SCRIPT1014:无效字符test.js,第1行,字符1”

test.js: test.js:

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

test.js is UTF-8, so there is no reading problem.. there is something else test.js是UTF-8,所以没有阅读问题......还有别的东西

What's wrong? 怎么了? Any ideas? 有任何想法吗? Thanks in advance! 提前致谢!

  1. Try to resave JS in "UTF-8 without BOM" encoding 尝试在“UTF-8无BOM”编码中重新保存JS
  2. Try to place JS to remote server as http://example.com/test.js 尝试将JS作为http://example.com/test.js放置到远程服务器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM