简体   繁体   English

jQuery mobile:如何仅在首次加载页面时显示弹出窗口?

[英]Jquery mobile: How to show popup only when first loading the page?

I started developing my first mobile app using jquery mobile. 我开始使用jquery mobile开发第一个移动应用程序。 So far it has been going nicely, but I am not able to solve a specific popup behaviour. 到目前为止,一切进展顺利,但是我无法解决特定的弹出窗口行为。

What I want it for a popup to show once the user loads the app. 我希望用户加载应用程序后显示的弹出窗口是什么。 This popup should be similar to a add to home popup like you see in many apps. 就像在许多应用程序中看到的那样,此弹出窗口应类似于添加到主弹出窗口。 It is intended to point the users direction to the fixed footer with some important buttons. 旨在通过一些重要的按钮将用户指向固定的页脚。 I managed to insert this popup and open it on page load, but there are two things I am not able to do. 我设法插入了此弹出窗口并在页面加载时将其打开,但是有两件事我做不到。

  1. My popup loads and disappears, which I want, and that is all OK. 我的弹出窗口加载并消失了,这是我想要的,一切正常。 However, once you reload the page, or navigate to another and go back, it opens up again. 但是,一旦您重新加载页面或导航到另一个页面并返回,它就会再次打开。 This is annoying for the user. 这对用户来说很烦。 I would like it to open up only the first time you load the home page. 我希望它仅在您首次加载主页时打开。

  2. I would like to position the popup above the footer, so not over it, but above. 我想将弹出窗口放在页脚上方,所以不要放在页脚上方,而是放在上方。 How would I do this? 我该怎么做? Do I use x and y, and if yes how? 我是否使用x和y,如果是,如何使用?

  3. Is there a way for the overlay effect to obscure the whole page, except the footer? 有没有一种方法可以使覆盖效果遮盖整个页面(页脚除外)?

Thank you. 谢谢。

Here is the code: 这是代码:

    <div data-role="page" id="home">
<div data-position="fixed" data-role="header" data-theme="d">
<h1>Prva pomoć</h1>
    <button data-icon="info" data-iconpos="right"></button>
</div>
<div data-role="content">   
    <ul data-role="listview" data-divider-theme="d">
<li data-role="list-divider">Ne reagira i ne diše
</li>
<li><a href="#page2">Oživljavanje</a></li>
    <li><a href="#page3">Oživljavanje + AVD</a></li>
<li data-role="list-divider">Ne reagira, ali diše</li>
    <li><a href="#page4">Bočni položaj</a></li>
    <li data-role="list-divider">Ostalo</li>
    <li><a href="#page4">Gušenje</a></li></ul></div> 
    <div id="popspot"></div>
    <div data-role="popup" id="popup" data-transition="slidedown" data-position-to="#popspot" data-theme="a" data-overlay-theme="e" data-history="true">
<p>U slučaju hitnoće koristi ovaj izbornik!<p></div>
        <script type="text/javascript" language="JavaScript">
            $(":jqmData(role='page'):last").on("pageshow", function(event) {
              $("#popup", $(this)).popup("open");
               setTimeout(function(){
      $("#popup").popup("close");
    }, 3000);
            });
        </script>
    <div data-role="footer" id="hitnizbor" data-position="fixed" class="nav-glyphish-example">
<div class="nav-glyphish-example" data-grid="b" data-role="navbar" data-theme="e">
<ul>
    <li><a href="#popup" data-rel="popup" id="chat" data-icon="custom">Zovi Hitnu</a></li>
    <li><a href="#" id="email" data-icon="custom">Oživljavanje</a></li>
    <li><a href="#" id="skull" data-icon="custom">Osobni podaci</a></li>
</ul>
</div>

You can use sessionStorage or localStorage to keep track of the information related to whether pop up is shown or not. 您可以使用sessionStorage或localStorage来跟踪与是否显示弹出窗口有关的信息。

You code would be something as below 您的代码将如下所示

if (localStorage.popUpShown != 'true') {
        // window will position the pop up to center
        $('#popup').popup('open', {positionTo: 'window'});

        localStorage.popUpShown = 'true';
        setTimeout(function () {
            $("#popup").popup("close");
        }, 3000);
    }
else{
        // Can remove this alert in development enviornment.
        alert('already shown the popup');
    }

you can check the live fiddle here http://jsfiddle.net/mayooresan/MyaE9/ 您可以在这里查看现场小提琴 http://jsfiddle.net/mayooresan/MyaE9/

Also did some tweaking to your html. 还对您的html做了一些调整。 You had markup errors in your html page. 您的html页面中存在标记错误。

<div data-role="page" id="home">
    <div data-position="fixed" data-role="header" data-theme="d">

<h1>Prva pomoć</h1>

        <button data-icon="info" data-iconpos="right"></button>
    </div>
    <div data-role="content">
        <ul data-role="listview" data-divider-theme="d">
            <li data-role="list-divider">Ne reagira i ne diše</li>
            <li><a href="#page2">Oživljavanje</a>

            </li>
            <li><a href="#page3">Oživljavanje + AVD</a>

            </li>
            <li data-role="list-divider">Ne reagira, ali diše</li>
            <li><a href="#page4">Bočni položaj</a>

            </li>
            <li data-role="list-divider">Ostalo</li>
            <li><a href="#page4">Gušenje</a>

            </li>
        </ul>
        <div id="popspot"></div>
        <div data-role="popup" id="popup" data-transition="slidedown" data-position-to="#popspot" data-theme="a" data-overlay-theme="e" data-history="true">
            <p>U slučaju hitnoće koristi ovaj izbornik!</p>
        </div>
    </div>
    <div data-role="footer" id="hitnizbor" data-position="fixed" class="nav-glyphish-example">
        <div class="nav-glyphish-example" data-grid="b" data-role="navbar" data-theme="e">
            <ul>
                <li><a href="#popup" data-rel="popup" id="chat" data-icon="custom">Zovi Hitnu</a>

                </li>
                <li><a href="#" id="email" data-icon="custom">Oživljavanje</a>

                </li>
                <li><a href="#" id="skull" data-icon="custom">Osobni podaci</a>

                </li>
            </ul>
        </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM