我正在为Windows Phone 7开发应用程序,并且正在使用Phonegap模板。 一切都看起来很完美,但现在我坚持试图在浏览器中打开PDF文件。 我尝试了以下方法,但这不起作用,因为PDF的URL超过了2048个字符限制(这是一个数据url)。该代码在deviceReady事件被触发后运行。在Windows Phone中打开PDF文件
var ref = window.open('http://www.google.com', '_blank', 'location=no');
ref.addEventListener('loadstart', function() { alert(event.url); });
现在,我想保存PDF文件的存储,然后我试图把它的浏览器中打开,但浏览器不显示任何东西。我从cordovalib编辑InAppBrowser.cs代码,并在调用browser.navigate(loc)之前添加了以下几行代码:
private void ShowInAppBrowser(string url)
{
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
FileStream stream = store.OpenFile("test.pdf", FileMode.Create);
BinaryWriter writer = new BinaryWriter(stream);
var myvar = Base64Decode("the big data url");
writer.Write(myvar);
writer.Close();
if (store.FileExists("test.pdf")) // Check if file exists
{
Uri loc = new Uri("test.pdf", UriKind.Relative);
...
}
}
该代码返回以下错误: 日志:“错误的错误回调:InAppBrowser1921408518 =类型错误:无法获取属性‘URL’的值:对象为null或undefined”
我不想使用ComponentOne。
任何帮助将不胜感激!
非常感谢托尼!你的回复帮了我很多。 – 2013-03-26 17:26:26
那么这是否意味着我们无法在WP8中通过自己的应用程序打开pdf或word文档?我也有同样的问题,我已经在localStorage下载了一个pdf文件,并且一旦下载,我想把它展示给用户,任何建议如何做到这一点? – Debhere 2013-03-27 07:00:10
@Debhere检查http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206987(v=vs.105).aspx了解更多信息。 – 2013-03-27 09:02:06