【发布时间】:2017-03-15 05:44:21
【问题描述】:
我从服务器下载了一个 html 内容,并将其存储在 Windows 存储文件夹 (Windows.Storage.ApplicationData.Current.LocalFolder.Path) 中。当我使用 window.location.href="ms-appdata:///local/inde.html" 导航到该页面时,没有任何反应。当我使用 webView.navigate("ms-appdata:///local/index.html") 导航时,它会显示页面,但我的任何 javascript 都没有被执行。任何事情都会更有帮助。
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function (id) {
var plugin = new RuntimeComponent.Class;
plugin.InitializeApp().then(function (response) {
try{
(new Windows.UI.Popups.MessageDialog(response, "Title")).showAsync()
}catch(e){
}
});
}
};
app.initialize();
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>Hello World</title>
</head>
<body>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>
【问题讨论】:
-
您应该将您的 html 放在本地文件夹下的子文件夹中。比如
ms-appdata:///local/folder/file.html。 -
@Tao:是的,我的 html 已经在一个文件夹中了。仅供参考,我提到的直接文件。
标签: html windows webview uwp windows-10-universal