开发者

Enable Javascript for local files in VBA WebBrowser Control

开发者 https://www.devze.com 2023-02-09 09:13 出处:网络
I find it rather perplexing that IE7 enables Javascript by default on the Internet zone, but disables it for local HTML files [My Computer zone] (the internet is now more secure than your local comput

I find it rather perplexing that IE7 enables Javascript by default on the Internet zone, but disables it for local HTML files [My Computer zone] (the internet is now more secure than your local computer?), but anyway...

I have an application in VBA using the WebBrowser control to open a local HTML file (say, file:///C:\somefile.html) which has Javascript in it. I'd like for this Javascript to be exec开发者_运维问答uted. Is there any way (from VBA code) to force the browser to allow this Javascript? (taking into consideration that it's disabled by default)

It would be ideal if I wouldn't have to rely on registry editing of any sorts, or tell the user of the application to change their Internet Explorer settings. I've also tried setting up a localhost webserver and serving the file from there. Obviously works perfectly since IE considers this to be the Internet zone, but I'd like it if I didn't have to try coding a webserver from VBA either.

System is Windows XP with IE7.

Thanks


Okay, probably not a "true" solution, but is enough for my needs. One can use the WebBrowser.Document.parentWindow.execScript function to inject Javascript into the page. I guess it may be possible to implement something similar to Prototype's evalScripts function here so that it effectively evaluates any scripts on the page. One may need to double-check that the scripts haven't already been allowed by potentially different security settings. I don't know how it affects linked script files.

(for my own application, I control the HTML file so I just extract all the Javascript into a separate file and execute it using the above method).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号