启动默认浏览器与HTML文件,然后跳转到特定的锚 [英] Launching default browser with html from file, then jump to specific anchor

查看:164
本文介绍了启动默认浏览器与HTML文件,然后跳转到特定的锚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要打开从程序根目录下的HTML文件,并把它跳转到指定的锚。我可以打开该文件用一个简单的

I need to open an html file from the program root directory and have it jump to a specified anchor. I can open the file perfectly fine with a simple

System.Diagnostics.Process.Start(site.html)

System.Diagnostics.Process.Start("site.html")

但只要我尝试锚添加到它不再能够找到该文件的末尾。

but as soon as I try to add the anchor to the end it ceases to be able to find the file.

我能够把锚那里仍然有它以

I was able to put the anchor in there and still have it launch with

字符串锚

锚=启动文件:///+环境。.CurrentDirectory.ToString()更换(\,/)+
/site.html#Anchor
System.Diagnostics.Process.Start(锚);

Anchor = "file:///" + Environment.CurrentDirectory.ToString().Replace("\", "/") + "/site.html#Anchor"; System.Diagnostics.Process.Start(Anchor);

然而只要浏览器启动则丢弃该锚。有什么建议?

However as soon as the browser launches it drops the anchor. Any suggestions?

推荐答案

您可能需要包含整个URL引号中保存任何特殊字符(如#) 。或空格

You may need to enclose the entire URL in quotation marks to preserve any special characters (such as the #) or spaces.

尝试:

string Anchor = String.Format("\"file:///{0}/site.html#Anchor\"", Environment.CurrentDirectory.ToString().Replace("\\", "/"));
System.Diagnostics.Process.Start(Anchor);

这篇关于启动默认浏览器与HTML文件,然后跳转到特定的锚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆