我需要从程序根目录打开一个html文件并让它跳转到指定的锚点。我可以通过简单的操作完美地打开该文件
System.Diagnostics.Process.Start("site.html")
但一旦我尝试将锚点添加到末尾,它就无法找到该文件。
我能够将锚放在那里并且仍然可以启动它
绳锚
Anchor = "file:///" + Environment.CurrentDirectory.ToString().Replace("\", "/") +
"/site.html#Anchor";
System.Diagnostics.Process.Start(Anchor);
然而,一旦浏览器启动,它就会失去锚点。有什么建议么?
using Microsoft.Win32; // for registry call.
private string GetDefaultBrowserPath()
{
string key = @"HTTP\shell\open\command";
using(RegistryKey registrykey = Registry.ClassesRoot.OpenSubKey(key, false))
{
return ((string)registrykey.GetValue(null, null)).Split('"')[1];
}
}
private void GoToAnchor(string url)
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = GetDefaultBrowserPath();
p.StartInfo.Arguments = url;
p.Start();
}
// use:
GoToAnchor("file:///" + Environment.CurrentDirectory.ToString().Replace("\", "/") + "/site.html#Anchor");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)