【发布时间】:2015-02-24 01:15:36
【问题描述】:
我正在尝试将我的项目本地的 js 和 css 资源文件包含在作为字符串加载到 WPF WebBrowser 控件中的 html 页面上。
该项目为桌面应用程序构建一个 dll。使用 Visual Studio 2013 和 C#。
HTML 在 WebBrowser 中加载,但出现与包含 JS 文件相关的错误。
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>
我收到如下错误弹出窗口:
An error has occurred in the script on this page.
URL: aboutC:\MyDir\MyProject\bin\Debug\Resources/myscript.js
它在 URL 前面加上“关于”。我可能还需要更改斜线。 我尝试了很多东西。 "about" 总是放在前面。
也尝试使用独立存储,但这不适用于我的项目: http://msdn.microsoft.com/library/windows/apps/ff431811(v=vs.105).aspx
【问题讨论】:
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
标签: c# wpf webbrowser-control