ios phonegap的window.unload不执行
本帖最后由 每天成长一点点 于 2015-10-26 11:55 编辑<html> <head> <!-- Customize this policy to fit your own app's needs. For more guidance, see: https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy Some notes: * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly * Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this: * Enable inline JS: add 'unsafe-inline' to default-src --> <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"> <meta http-equiv='Content-Type' Content="text/html;charset=utf-8"/> <link rel="stylesheet" type="text/css" href="css/index.css"> <link rel="stylesheet" Type="text/css" href="css/mainView.css"> <title>Hello World</title> <script type="text/javascript" charset="utf-8" language="javascript" src="cordova.js"></script> </head> <body> <div class="mainView" onclick='event.cancelBubble=true'> </br> <button>按钮</button></br> <button>按钮1</button> </div>
</body> <script type="text/javascript"> window.onload = inOpen; function inOpen(){ console.warn("11111111111111++++++"); } </script> </html>界面可以显示两个按钮 但是却不执行window.load 按钮的函数也执行不了 代码放到webStorm就可以执行
Phonegap的deviceready事件
该事件是在 PhoneGap 载入完成后 发生的事件
相当于程序的入口功能
如下 onDeviceReady 函数
document.addEventListener("deviceready", yourCallbackFunction, false);
简单例子:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
// Now safe to use device APIs
}
完整例子:
<!DOCTYPE html>
<html>
<head>
<title>Device Ready Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load //
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
} // device APIs are available //
function onDeviceReady() {
// Now safe to use device APIs
}
</script>
</head>
<body onload="onLoad()">
</body>
</html>
admin 发表于 2015-10-26 20:41
Phonegap的deviceready事件
该事件是在 PhoneGap 载入完成后 发生的事件
谢谢 已经解决了 admin 发表于 2015-10-26 20:41
Phonegap的deviceready事件
该事件是在 PhoneGap 载入完成后 发生的事件
谢谢 解决了
页:
[1]