【问题标题】:$.mobile.changePage without ajax$.mobile.changePage 没有 ajax
【发布时间】:2012-07-25 06:16:20
【问题描述】:

您好,我使用了$.mobile.changePage('test.html'); 从一个页面导航到另一个页面。这在 android、symbian 和 blackberry6+ 中运行良好。但我也希望我的应用程序在 blackberry5 上运行。 Blackberry5 不支持 ajax,因此 $.mobile.changePage('test.html'); 不支持它。

出于这个原因,我使用window.open("test.html");window.location.href = "test.html"; 在这里它在包括blackberry4.6+ 在内的所有平台上都能完美运行。但现在的问题是我在 test.html 中有标题:

     <div data-role="header" align="center">

        <a href="#" data-rel="back" data-icon="arrow-l">Back</a>
            <h1>Test.html</h1>
        <a href="MainMenu.html"  data-icon="grid">Menu</a>


    </div>

但是现在后退按钮不起作用。如果我使用$.mobile.changePage('test.html'); 进行导航,则返回按钮可以完美运行,但不适用于window.open("test.html");window.location.href = "test.html";

因此我使用会话并在单击后退按钮时强行调用页面。如:

<script type="application/javascript">

            function redirect(url)
            {
                alert("inside redirect:"+url);
                window.location = url;
            }

        </script>

        <div data-role="navbar">
            <ul>

                <li> <a onclick="redirect( getCookie('paged'))" data-icon="back" data-iconpos="notext" data-direction="reverse" class="ui-btn-left jqm-home">Back</a></li>
                <li> <a onclick="redirect(getCookie('paged'))" data-icon="back" data-iconpos="notext" data-direction="reverse" class="ui-btn-left jqm-home">Back</a></li>

            </ul>
        </div>

现在这里的后退按钮也可以正常工作,但是当我点击硬件后退按钮时,它会再次转到之前的页面。

我如何在没有 ajax 的情况下使用$.mobile.changePage(...),以便我可以在包括 blackberry4.6+ 在内的所有平台上使用它

任何建议将不胜感激。提前致谢。

【问题讨论】:

    标签: jquery jquery-ui jquery-plugins jquery-mobile cordova


    【解决方案1】:

    我尝试使用全局配置禁用 ajax,但由于某种原因它对我来说不起作用。

    我尝试如下,它成功了

    window.location.href="myfile.html";
    

    【讨论】:

      【解决方案2】:

      您是否尝试将全局属性$.mobile.ajaxEnabled 设置为false?见http://jquerymobile.com/demos/1.1.1/docs/api/globalconfig.html。据说“jQuery Mobile 将尽可能通过 Ajax 自动处理链接点击和表单提交”。我现在不确定它是否也会影响$.mobile.changePage,但也许值得一试......

      【讨论】:

      • 我试过 '$.mobile.ajaxEnabled = false; '但没有运气。感谢您的建议。
      【解决方案3】:

      你可以使用这个功能。

      $.mobile.changePage('#gototestpage');
      

      但是有一些限制。您必须将代码保留在另一个 div 中的同一页面中,就像这样,

      <div id="gototestpage"> --- Your Code here ----- </div>
      

      【讨论】:

      • Blackberry5 不支持 ajax,因此我不能使用 $.mobile.changePage。
      【解决方案4】:

      我已经尝试了这两种解决方案,都对我有用:

      window.location.href = yourpageurl;
      

      $.mobile.ajaxEnabled = false;
      $(":mobile-pagecontainer").pagecontainer( "change", yourpageurl);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多