我想创建windows8移动应用程序作为其他web应用程序的容器。我的意思是这个应用程序会从我的服务器上下载HTML,CSS和Javascript包,保存到数据库,用户可以打开这些下载的应用程序。它适用于安卓和iOS,但不适用于Win8。
下载并保存到数据库工作。为了打开下载的应用程序,我创建了临时文件夹,保存所有文件并创建链接
<a href="file://path_to_index.html">Open</a>但是链接没有打开。我猜Windows安全策略不允许在移动应用程序中打开本地链接。
你对此有什么解决方案,或者有什么替代方法的想法吗?
编辑:
根据jakerella的说法,我尝试将文件写到本地存储,并在ms-webview中打开它,但它不起作用。函数webview.navigate('ms-appdata:///local/index.html')引发异常:参数错误
Javascript:
$(function () {
$('#my_button').click(function () {
var HTML_CONTENT = '<!DOCTYPE html> <html> <head> <title></title> </head> <body> <button id="btn">Click me!</button> <div id="content"></div> <script type="text/javascript" src="index.js"></script> </body> </html>';
var JS_CONTENT = 'document.getElementById("btn").onclick=function(){var a=document.getElementById("content");a.innerHTML="Clicked!"};';
var localFolder = Windows.Storage.ApplicationData.current.localFolder;
localFolder.createFileAsync("index.html", Windows.Storage.CreationCollisionOption.replaceExisting).then(function (file) {
Windows.Storage.FileIO.writeTextAsync(file, HTML_CONTENT).then(function() {
localFolder.createFileAsync("index.js", Windows.Storage.CreationCollisionOption.replaceExisting).then(function (file2) {
Windows.Storage.FileIO.writeTextAsync(file2, JS_CONTENT).then(function () {
try {
var wv = $('#wv')[0];
wv.navigate('ms-appdata:///local/index.html');
} catch (e) {
console.log(e.message);
}
});
});
});
});
});
});和HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>App1</title>
<!-- WinJS references -->
<link href="//Microsoft.WinJS.2.0/css/ui-dark.css" rel="stylesheet" />
<script src="//Microsoft.WinJS.2.0/js/base.js"></script>
<script src="//Microsoft.WinJS.2.0/js/ui.js"></script>
<script src="js/jquery-2.1.0.min.js"></script>
<script src="js/script.js"></script>
<!-- App1 references -->
<link href="/css/default.css" rel="stylesheet" />
<script src="/js/default.js"></script>
</head>
<body>
<button id="my_button">Open page</button>
<x-ms-webview id="wv">
</x-ms-webview>
</body>
</html>EDIT2:
好了,它起作用了!我在这里找到了解决方案:http://blogs.windows.com/windows/b/appbuilder/archive/2013/10/01/blending-apps-and-sites-with-the-html-x-ms-webview.aspx
发布于 2014-05-09 23:30:03
在我看来,你有两种方法。
其中之一就是使用x-ms-webview,这就是您所发现的。
另一种方法是使用微软强烈不推荐的execUnsafeLocalFunction,通过代码将html直接设置为一个元素,但我猜你可以负责任地使用它。
https://stackoverflow.com/questions/21576322
复制相似问题