JQuery Mobile popup with history=false autocloses

杀马特。学长 韩版系。学妹 提交于 2019-11-28 08:57:41

问题


I'm trying to show a popup but the popup disappears automatically, without the history=false the popup stays visible but then on closing the popup the browser back action is triggered

<div data-role="page" id="indexpage">
    <div data-role="popup" data-history="false" id="appPopup">test popup</div>
    <script>
    $("#indexpage").on("pageshow", function () {
        $("#appPopup").popup("open");
    });
    </script>
</div>

Check what happens here: http://jsfiddle.net/francisdb/ThtfZ/

Any idea on how to fix this?


回答1:


Working example: http://jsfiddle.net/Gajotres/2EL5R/

$("#indexpage").on("pageshow", function () {
    var popup = setInterval(function(){
        $("#appPopup").popup("open");
        clearInterval(popup);
    },1);
});

Webkit browsers hate popup open, so setinterval needs to be used to trigger it. Same thing goes for a few other jQuery Mobile functionalities.




回答2:


I had the same issue looking to solve this now for several hours. The solution suggested by Gajotres seamed to work first, but in the end did not on all devices. I tested with several android, desktop and iOS Browsers.

The problem in my case was an AdSense Banner, that was hidden by the popup.

Google AdSense will notice that the banner is no longer visible and close the popup upon loading of the AdSense banner. Removed the banner, and it workes now perfectly. Other AdSense banners on the page, which are not hidden by the popup will not affect the popup functionality.



来源:https://stackoverflow.com/questions/15830213/jquery-mobile-popup-with-history-false-autocloses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!