Process.Start(url),url 中带有锚点

发布于 2024-08-24 12:35:43 字数 303 浏览 4 评论 0原文

我正在尝试使用 Process.Start 在默认浏览器中启动本地 html 文件。

示例 url 如下:

"file:///C:/Documentation/HelpContent/default_CSH.htm#SectionA/Topic1.htm"

问题是,由于某种原因,“#SectionA/Topic1.htm”位被删除,因此该信息不会传递到浏览器。但对于非本地 url 来说它确实可以正常工作。

有谁知道我如何才能让它发挥作用,或者这是某种预防性安全问题?

谢谢

I am trying to use Process.Start to launch a local html file in the default browser.

An example url is as follows:

"file:///C:/Documentation/HelpContent/default_CSH.htm#SectionA/Topic1.htm"

Problem is, the "#SectionA/Topic1.htm" bit gets stripped off for some reason, so that this information isn't passed to the browser. It does however work fine for a non-local url.

Does anyone know how I can get this to work or is it some sort of preventative security issue?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清风夜微凉 2024-08-31 12:35:43

iexplore.exe 上使用 Process.Start,以便您可以专门指定 URL 作为其参数:

System.Diagnostics.Process.Start("iexplore.exe", @"file:///c:/dir/file.html#anchor");

Use Process.Start on iexplore.exe, so that you can specify the URL specifically as its argument:

System.Diagnostics.Process.Start("iexplore.exe", @"file:///c:/dir/file.html#anchor");
余罪 2024-08-31 12:35:43

如果您让操作系统确定默认浏览器,则在浏览器中启动带有锚点的 URL 将不起作用。实现此功能的唯一方法是将浏览器的可执行文件指定为为 IE 编写的二进制编码器。 Firefox 的工作方式相同。

最好的解决方案显然是从注册表中确定默认浏览器的路径,然后专门调用该可执行文件。

Launching a URL with an anchor in a browser does not work if you let the OS determine the default browser. The only way to make this work is to specify the browser's executable as binarycoder wrote for IE. It works the same way for Firefox.

The best solution is obviously to determine the path to the default browser from the registry and then specifically call that executable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文