简体   繁体   English

无法在IE中执行本地脚本

[英]Cannot execute local script in IE

I created a Browser Helper Object for IE8 in order to run a javascript located on my computer. 我为IE8创建了浏览器帮助程序对象,以便运行位于计算机上的javascript。 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. 但是结果是E_INVALIDARG,这很可能是由脚本地址引起的。 Is it possible to run the script from my computer without lowering security settings for Internet Zone? 是否可以在不降低Internet Zone安全性设置的情况下从计算机运行脚本? I tried to set security settings for Trusted Sites to minimum and added to trusted sites 'file://localserver', but to no avail. 我试图将“受信任的站点”的安全设置设置为最低,并添加到“ file:// localserver”的受信任站点,但无济于事。

EDIT: More specifically, I get the following error message within the IE window: 编辑:更具体地说,我在IE窗口中收到以下错误消息:

Message: Invalid character

Line: 1

Char: 1

Code: 0

URI: file:///L:/prg/Web/ieplugin/ieplugin.js

Internet Explorer does not allow the use of file:// protocol URIs within non-File:// delivered pages. Internet Explorer不允许在非File://交付的页面中使用file://协议URI。 This change was made back in 2011 and applies only to INTERNET and RESTRICTED ZONE sites. 这项更改是在2011年进行的,仅适用于INTERNET和RESTRICTED ZONE网站。

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. 有关详细信息,请参见http://blogs.msdn.com/b/ieinternals/archive/2011/08/12/internet-explorer-9.0.2-update-changes-file-protocol-and-cookie-naming.aspx

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. 要解决此问题,请让您的扩展将目标脚本的内容加载到BSTR中,然后使用该BS​​TR传递给execScript。

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

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