我无法在 iOS 手机上使用 Phonegap 打开弹出对话框
I cannot open popup dialog with Phonegap on iOS mobile
我在 iOS 平台上遇到 Phonegap 的奇怪问题。在 Android 上,"popup" 工作正常。
我有这个代码:
<button data-rel="popup" data-position-to="window" data-transition="pop" id="prueba23">Botón</button>
<div data-role="popup" id="popupDialog">
<div data-role="header" data-theme="a" style="top:-21px">
<h1>Delete Page?</h1>
</div>
<div role="main">
<h3 class="ui-title">Are you sure you want to delete this page?</h3>
<p>This action cannot be undone.</p>
</div>
<div data-role="footer">
<div data-role="navbar">
<ul>
<li><a href="#test-ries" data-role="button" data-icon="info" data-iconpos="notext">Volver</a></li>
</ul>
</div>
</div>
</div>
<script>
$('#prueba23').on('tap', function(e){
e.preventDefault();
$('#popupDialog').popup('open');
});
</script>
在 iOS 平台上,我第一次点击按钮时,弹出窗口出现并在一秒钟后消失。在第二次(和第三次、第四次……)时,弹出窗口正常工作。第一次点击按钮时只有一个奇怪的行为。
这是我录制的示例视频:https://www.youtube.com/watch?v=HTkrUr1vpsM&feature=youtu.be
谢谢。
我假设您正在 iOS 9 上进行测试,并且从您的 HTML 的外观来看,在您的应用程序中使用 jQuery Mobile。如果是这样,您遇到了 iOS 9 中引入的错误/"feature",即 window.location.hash
的设置在 iOS 9.0 UIWebview 中是异步的(由 Cordova/Phonegap) - 详见 this bug report。
这会导致使用 jQuery 移动设备时出现问题,默认情况下使用 window.location.hash
在 "pages" 之间导航。它还会导致使用此机制的 popups/dialogs/select 菜单出现问题,因此会出现您所看到的症状。请注意,iOS 8 和 9 上的 Safari 使用 WKWebView 而不是 UIWebView,因此在 iOS 9 上的浏览器中查看 JQM 站点不会遇到这些问题。
您可以通过阻止 jQuery Mobile 自动 listening/using location.hash:
来修复 iOS 9.0 Cordova 应用程序上的这些问题
$(document).on("deviceready", function(){
$.mobile.hashListeningEnabled = false;
});
但是,我发现这对 Android 有副作用,例如导致硬件后退按钮不起作用,所以我专门针对 iOS 9 使用 cordova-plugin-device:
$(document).on("deviceready", function(){
if(device.platform === "iOS" && parseInt(device.version) === 9){
$.mobile.hashListeningEnabled = false;
}
});
这解决了我的导航和弹出窗口问题,但是 others have said 弹出窗口 data-history="false"
的设置 div 解决了他们的问题,所以如果以上方法不起作用,请尝试这也是。
或者,您可以对 iOS 9+ 使用 this plugin to use the new WKWebView on iOS 8 and 9 with your Cordova app. cordova-ios 3 still uses UIWebView due to a bug in WKWebView in iOS 8, but the upcoming cordova-ios 4 will support a WKWebView core plugin。请注意,由于其更严格的安全性,将 WKWebView 与 Cordova/Phonegap 应用程序一起使用时还有其他注意事项,例如在 XHR 响应中需要 CORS headers。
我在 iOS 平台上遇到 Phonegap 的奇怪问题。在 Android 上,"popup" 工作正常。 我有这个代码:
<button data-rel="popup" data-position-to="window" data-transition="pop" id="prueba23">Botón</button>
<div data-role="popup" id="popupDialog">
<div data-role="header" data-theme="a" style="top:-21px">
<h1>Delete Page?</h1>
</div>
<div role="main">
<h3 class="ui-title">Are you sure you want to delete this page?</h3>
<p>This action cannot be undone.</p>
</div>
<div data-role="footer">
<div data-role="navbar">
<ul>
<li><a href="#test-ries" data-role="button" data-icon="info" data-iconpos="notext">Volver</a></li>
</ul>
</div>
</div>
</div>
<script>
$('#prueba23').on('tap', function(e){
e.preventDefault();
$('#popupDialog').popup('open');
});
</script>
在 iOS 平台上,我第一次点击按钮时,弹出窗口出现并在一秒钟后消失。在第二次(和第三次、第四次……)时,弹出窗口正常工作。第一次点击按钮时只有一个奇怪的行为。
这是我录制的示例视频:https://www.youtube.com/watch?v=HTkrUr1vpsM&feature=youtu.be 谢谢。
我假设您正在 iOS 9 上进行测试,并且从您的 HTML 的外观来看,在您的应用程序中使用 jQuery Mobile。如果是这样,您遇到了 iOS 9 中引入的错误/"feature",即 window.location.hash
的设置在 iOS 9.0 UIWebview 中是异步的(由 Cordova/Phonegap) - 详见 this bug report。
这会导致使用 jQuery 移动设备时出现问题,默认情况下使用 window.location.hash
在 "pages" 之间导航。它还会导致使用此机制的 popups/dialogs/select 菜单出现问题,因此会出现您所看到的症状。请注意,iOS 8 和 9 上的 Safari 使用 WKWebView 而不是 UIWebView,因此在 iOS 9 上的浏览器中查看 JQM 站点不会遇到这些问题。
您可以通过阻止 jQuery Mobile 自动 listening/using location.hash:
来修复 iOS 9.0 Cordova 应用程序上的这些问题$(document).on("deviceready", function(){
$.mobile.hashListeningEnabled = false;
});
但是,我发现这对 Android 有副作用,例如导致硬件后退按钮不起作用,所以我专门针对 iOS 9 使用 cordova-plugin-device:
$(document).on("deviceready", function(){
if(device.platform === "iOS" && parseInt(device.version) === 9){
$.mobile.hashListeningEnabled = false;
}
});
这解决了我的导航和弹出窗口问题,但是 others have said 弹出窗口 data-history="false"
的设置 div 解决了他们的问题,所以如果以上方法不起作用,请尝试这也是。
或者,您可以对 iOS 9+ 使用 this plugin to use the new WKWebView on iOS 8 and 9 with your Cordova app. cordova-ios 3 still uses UIWebView due to a bug in WKWebView in iOS 8, but the upcoming cordova-ios 4 will support a WKWebView core plugin。请注意,由于其更严格的安全性,将 WKWebView 与 Cordova/Phonegap 应用程序一起使用时还有其他注意事项,例如在 XHR 响应中需要 CORS headers。