C# 包括静态JS和CSS WebBrowser控件
我试图在html页面上包含项目本地的js和css资源文件,这些文件作为字符串加载到WPF WebBrowser控件中 该项目为桌面应用程序构建一个dll。使用Visual Studio 2013和C# HTML加载到WebBrowser中,但是我得到了与包含JS文件相关的错误C# 包括静态JS和CSS WebBrowser控件,c#,wpf,webbrowser-control,C#,Wpf,Webbrowser Control,我试图在html页面上包含项目本地的js和css资源文件,这些文件作为字符串加载到WPF WebBrowser控件中 该项目为桌面应用程序构建一个dll。使用Visual Studio 2013和C# HTML加载到WebBrowser中,但是我得到了与包含JS文件相关的错误 private void Window_Loaded(object sender, RoutedEventArgs e) { string page = GetPage();
private void Window_Loaded(object sender, RoutedEventArgs e)
{
string page = GetPage();
if (page != null)
{
string resourcePath = System.IO.Path.GetFullPath("Resources/");
// Try setting an absolute path
page = page.Replace("Resources/", resourcePath);
this.webbrowser.NavigateToString(page);
}
}
html字符串中嵌入了以下内容:
<head>
<script language="JavaScript" src="Resources/myscript.js"></script>
<link rel="stylesheet" type="text/css" href="Resources/mystyle.css">
</head>
它在URL前面加上“about”。我可能还需要更改斜杠。
我尝试了很多东西。“about”总是有前缀的
还尝试使用IsolatedStorage,但这对我的项目不起作用:
调用
NavigateToString
时必须使用绝对URI。由于您不是,IE假定about:
为导致其失败的相对路径
或在随机高端口上使用
http://localhost:37458/path.css
调用NavigateToString
时必须使用绝对URI。由于您不是,IE假定about:
为导致其失败的相对路径
或在随机高端口上使用
http://localhost:37458/path.css
我已经编辑了你的标题。请看“”,其中的共识是“不,他们不应该”。我已经编辑了你的标题。请参阅“”,其中的共识是“不,他们不应该”。
An error has occurred in the script on this page.
URL: aboutC:\MyDir\MyProject\bin\Debug\Resources/myscript.js