.NET 4 WebBrowser 控件中的片段(锚点 #)与 Adobe PDF Reader 和 file:// 一起丢失
我创建了一个带有片段(也称为锚#)的 URI。
UriBuilder ub = new UriBuilder("file://path/doc.pdf");
ub.Fragment = "chapterX";
URL 在调试器中正确显示(ub -> file://path/doc.pdf#chapterX
)。但是当我将它分配给 WebBrowser 控件时,片段部分会丢失(片段的原因请参阅 PDF 打开参数)。
this._myWebBrowser.Url = ub.Uri;
// Alternative this._myWebBrowser.Navigate("file://path/doc.pdf#chapterX");
当我检查 this._myWebBrowser.Url
时,它显示 file://path/doc.pdf
。 this._myWebBrowser.Url.Fragment
为空 - 也是只读且无法分配。
正如 C.Haas 所示,这个概念通常有效,但由于某些原因,当资源是本地(!)pdf 文件时,它会失败。
摘要:
- 如果协议为 http,则有效
- ;如果资源为 .htm / .html,则有效 - 即使协议为 file://;
- 如果文件为 .pdf,协议为 http,则有效(与 1 相同。)
- 如果引用本地 pdf 文件、片段,则失败迷路了
有解决方法吗?
修订:
- 20110219 - 感谢 C.Haas 的更新。正如 Chris 所示,“.htm”可以,但“.pdf”则失败,并且仅当它引用本地资源时。
- 20110218 - 感谢 abatishchev 的一些发现:如果我使用
Navigate
它也不起作用,但Navigate
提供了一个框架名称。在这种情况下,会弹出一个外部 IE(因为控件的页面中没有框架),然后正确显示带有片段的 URL。这不是我想要的,但它告诉我 URL 本身是正确的,并且错误似乎在控制范围内。
I create an URI with a fragment (aka anchor #).
UriBuilder ub = new UriBuilder("file://path/doc.pdf");
ub.Fragment = "chapterX";
The url is shown correctly in the debugger (ub -> file://path/doc.pdf#chapterX
). But when I assign it to a WebBrowser control, the fragment part gets lost (reason for the fragment see PDF Open parameter).
this._myWebBrowser.Url = ub.Uri;
// Alternative this._myWebBrowser.Navigate("file://path/doc.pdf#chapterX");
When I check this._myWebBrowser.Url
it displays file://path/doc.pdf
. this._myWebBrowser.Url.Fragment
is empty - also readonly and cannot be assigned.
As C.Haas has shown below, the concept works in general, for some reasons it fails when the resource is a LOCAL(!) pdf file.
Summary:
- Works if protocol is http
- Works if resource is .htm / .html - even when protocol is file://
- Works if file is .pdf and protocol is http (same as 1.)
- Fails if refers to local pdf file, fragment gets lost
Any workaround for this?
Revisions:
- 20110219 - Update thanks to C.Haas. As Chris shows, OK with ".htm", but fails with ".pdf" and only if it refers to a local resource.
- 20110218 - Some finding thanks to abatishchev: If I use
Navigate
it does not work neither, butNavigate
offers to provide a frame name. In this case an external IE pops up (because there is no frame in the control's page) and then the URL with fragment is correctly displayed. Is not what I want, but it shows me the URL itself is correct and the bug seems to be within the control.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
怎么样
?
How about
?