3

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.

GreyWolf
  • 39
  • 5
  • Have you tried to replace the `file:///` link with an ordinary `http://` link? – Jørn E. Angeltveit Apr 26 '11 at 20:18
  • I just tried. The links with "http://" protocol do work. Links with "file://" do not. – GreyWolf Apr 26 '11 at 20:46
  • It seems that nothing happens when clicking on "file:///" links. I checked all event handlers that I defined, and none of them gets invoked. – GreyWolf Apr 26 '11 at 20:49
  • 2
    So it's probably prohibited. As MS says here http://msdn.microsoft.com/en-us/library/aa767731%28v=vs.85%29.aspx `Internet Explorer 6 Service Pack 1 (SP1) no longer allows browsing a local machine from the Internet zone` and maybe your memory stream considers IE as a site from the "Internet zone". –  Apr 26 '11 at 21:16
  • @daemon_x, @GreyWolf: Yes, the security settings due to local files that was my suspicion. I don't know if it's possible to change this. – Jørn E. Angeltveit Apr 26 '11 at 21:21
  • It won't work in IE either I predict. – David Heffernan Apr 27 '11 at 15:23

1 Answers1

1

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

Community
  • 1
  • 1