Question

I created a Browser Helper Object for IE8 in order to run a javascript located on my computer. Like browser extensions work in other browsers. I'm trying to execute the following code:

    IHTMLWindow2* pWindow;
    doc->get_parentWindow(&pWindow);

    hr = pWindow->execScript((BSTR)"var d=window.document,\
s=d.createElement('script'),\
h=d.getElementsByTagName('body')[0];\
s.src='file:///L:/prg/Web/ieplugin/ieplugin.js';\
h.appendChild(s);",
(BSTR)"JavaScript", &vResult);

But the result is E_INVALIDARG, which is caused most likely by the script address. Is it possible to run the script from my computer without lowering security settings for Internet Zone? I tried to set security settings for Trusted Sites to minimum and added to trusted sites 'file://localserver', but to no avail.

EDIT: More specifically, I get the following error message within the IE window:

Message: Invalid character

Line: 1

Char: 1

Code: 0

URI: file:///L:/prg/Web/ieplugin/ieplugin.js
Was it helpful?

Solution

Internet Explorer does not allow the use of file:// protocol URIs within non-File:// delivered pages. This change was made back in 2011 and applies only to INTERNET and RESTRICTED ZONE sites.

See http://blogs.msdn.com/b/ieinternals/archive/2011/08/12/internet-explorer-9.0.2-update-changes-file-protocol-and-cookie-naming.aspx for details.

To workaround this, instead have your extension load the contents of the target script into a BSTR, and use that BSTR to pass into execScript.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top