Delphi TWebBrowser 不响应单击文件超链接
我有 TWebBrowser 组件(Delphi 7),并且我从内存流加载了 HTML。页面的 HTML 代码加载良好,页面显示正确。但是,当我尝试单击任何带有地址(href 属性值)的超链接(例如“file:///C:/dir/page.html”)时,什么也没有发生。没有错误消息,浏览器也不会尝试转到另一个页面。 URL 100% 正确 - 当我将相同的网页加载到同一个 TWebBrowser 实例,但从硬盘驱动器上的文件而不是从内存流加载时,该链接确实可以正常工作。 有什么想法可能是错误的吗?
我尝试执行以下语句:
OleCheck(WebBrowser.SecurityManager.SetZoneMapping(URLZONE_INTRANET, 'about:blank', SZM_DELETE));
OleCheck(WebBrowser.SecurityManager.SetZoneMapping(URLZONE_TRUSTED, 'about:blank', SZM_DELETE));
OleCheck(WebBrowser.SecurityManager.SetZoneMapping(URLZONE_INTERNET, 'about:blank', SZM_DELETE));
OleCheck(WebBrowser.SecurityManager.SetZoneMapping(URLZONE_UNTRUSTED, 'about:blank', SZM_DELETE));
OleCheck(WebBrowser.SecurityManager.SetZoneMapping(URLZONE_LOCAL_MACHINE, 'about:blank', SZM_DELETE));
OleCheck(WebBrowser.SecurityManager.SetZoneMapping(URLZONE_LOCAL_MACHINE, 'about:blank', SZM_CREATE));
,但它们没有改变任何内容(它们执行正确,没有错误,即 HRESULT = S_OK 始终)。我必须说该组件实际上是 TEmbeddedWB(它具有 SecurityManager 属性),尽管 TWebBrowser 的行为方式相同 - 我刚刚重新检查了它。
我考虑诉诸使用临时目录中的文件。
感谢大家,我终于通过使用临时目录中的文件解决了这个问题。
I have TWebBrowser component (Delphi 7), and I loaded HTML from memory stream. The HTML code of the page loaded fine, the page is displayed correctly. But when I try to click on any hyperlink with addresses (href attribute value) like "file:///C:/dir/page.html", NOTHING happens. There is no error message, and the browser does not try to go to another page. The URL is 100% correct - when I load the same webpage to the same TWebBrowser instance, but from the file on hard drive, instead of from memory stream, the exactly this link works fine.
Any ideas what may be wrong?
I tried to execute the following statements:
OleCheck(WebBrowser.SecurityManager.SetZoneMapping(URLZONE_INTRANET, 'about:blank', SZM_DELETE));
OleCheck(WebBrowser.SecurityManager.SetZoneMapping(URLZONE_TRUSTED, 'about:blank', SZM_DELETE));
OleCheck(WebBrowser.SecurityManager.SetZoneMapping(URLZONE_INTERNET, 'about:blank', SZM_DELETE));
OleCheck(WebBrowser.SecurityManager.SetZoneMapping(URLZONE_UNTRUSTED, 'about:blank', SZM_DELETE));
OleCheck(WebBrowser.SecurityManager.SetZoneMapping(URLZONE_LOCAL_MACHINE, 'about:blank', SZM_DELETE));
OleCheck(WebBrowser.SecurityManager.SetZoneMapping(URLZONE_LOCAL_MACHINE, 'about:blank', SZM_CREATE));
, but they did not change anything (they were executed correctly, without errors, i.e., HRESULT = S_OK all the time). I must say that the component is actually TEmbeddedWB, (it has SecurityManager property) although TWebBrowser behaves the same way - I just re-checked it.
I think about resorting to using a file in the temporary directory.
Thanks to all, I finally worked around the problem by using the file in the temp dir.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于您的问题: Internet Explorer 本身是错误的
也就是说,自 IE 7 以来,如果不更改安全设置,就不可能从从 file:// 位置以外的其他位置加载的网站访问本地文件。最简单的解决方法就是正如您已经提到的,从本地驱动器的 file:// 位置打开网站,然后您将获得此访问权限。
以下是一些关于此内容的令人泪目的文章:
文件 URI 链接到IE7 中的本地文件夹无法正常工作
http://blogs.msdn.com/b/ freeassociations/archive/2005/05/19/420059.aspx
http://blogs.msdn.com/b/即/archive/2005/08/15/452006.aspx
To your question: The Internet Explorer itself is wrong
Namely, it's impossible to access local files from a website loaded from elsewhere than file:// location without changing your security settings since IE 7. The easiest workaround just as you already mentioned is to open the website from a file:// location from your local drive and then you'll get this access.
Here are some tearful articles about that:
File URI link to local folder in IE7 not working
http://blogs.msdn.com/b/freeassociations/archive/2005/05/19/420059.aspx
http://blogs.msdn.com/b/ie/archive/2005/08/15/452006.aspx