javascript - 在 WebBrowser 控件中加载本地文件

标签 javascript html windows-phone-7 browser local

我试图在 Windows Phone 7.1 上的 WebBrowser 中加载本地文件,但我总是收到异常或空白页。

我试过

Stream stream = Application.GetResourceStream(
                   new Uri("./Html/par/index.html", 
                   UriKind.Relative)).Stream;
using (StreamReader reader = new StreamReader(stream))
{
    // Navigate to HTML document string
    this.webBrowser.NavigateToString(reader.ReadToEnd());
}

这是在触发一个空白页面。

我将 index.html 和所有需要的文件 (css/js) 设置为 Content,并将 IsScriptEnable 设置为“true”。

你知道如何解决这个问题吗?

最佳答案

我认为路径不正确。

你的项目中有/Html/par目录吗?其次,index.html 是否设置为内容?

尝试

var rs = Application.GetResourceStream(new Uri("myFile.html", UriKind.Relative));
using(StreamReader sr = new StreamReader(rs.Stream))
{
    this.webBrowser.NavigateToString(sr.ReadToEnd()); 
}

这可能有帮助 http://phone7.wordpress.com/2010/08/08/loading-a-local-html-file-in-the-webbrowser-control/

这可能有助于理解资源和内容之间的差异 http://invokeit.wordpress.com/2011/09/30/images-and-build-actio-settings-in-wp7/

此链接详细说明了如何加载文件和其他链接文件 http://transoceanic.blogspot.co.uk/2011/07/wp7-load-local-html-files-and-all.html

关于javascript - 在 WebBrowser 控件中加载本地文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11342153/

相关文章:

html - 固定元素不随滚动移动

javascript - 如何在当前页面中单击按钮时将另一个页面的日期选择器显示为弹出窗口?

javascript - 有没有办法通过javascript定位 anchor 标记中的href?

silverlight - 如何为 Phone7 Silverlight 应用程序使用 {x :Static . ..} 扩展?

javascript - 如何在VUE组件的Scoped区域中使用JSON数据

javascript - Angular2 Click 方法总是返回 false 值

silverlight - 如何使用 XNA 绘制动态网格

c# - 双指缩放大图像?

javascript - 如何在mongodb中查询数组

javascript - 在javascript中增加日历日期