I'm trying to create simple Internet Explorer 9 addon using .Net and BHO to load external js-file on page and execute it.
I created ieInstance_DownloadComplete (I also tried ieInstance_DocumentComplete, but things were worse) event handler:
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. But function eee() does not raise and i have an error: "SCRIPT1014: Invalid character test.js, line 1, character 1"
test.js:
function eee()
{
alert('ttt!');
};
test.js is UTF-8, so there is no reading problem.. there is something else
What's wrong? Any ideas? Thanks in advance!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.