jquery mobile url parameter not updating in browser, but getting correct one with “data-url”

血红的双手。 提交于 2019-12-05 17:55:06
Travis Nelson

I was able to resolve this issue by using the jqm.page.params plugin with help from this question on stackoverflow. Here is my code for using this plugin:

<html>
   <head>
      <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
      <script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>

      //Added the jqm.page.params plugin
      <script src="https://raw.github.com/jblas/jquery-mobile-plugins/35fcf54e2af380aa0e98e9f384572b02f58a1ea1/page-params/jqm.page.params.js"></script>
      <script>
         $("#page2").live('pageshow', function(e) {
            alert($(e.target).attr("data-url")+$.mobile.pageData.id);
            //$("#page_text").html("Page 2"+($(e.target).attr("data-url").replace(/.*id=/, "")));
            $("#page_text").html("Page 2"+$.mobile.pageData.id);

         });
         $(document).bind("pagebeforechange", function( event, data ) {
            $.mobile.pageData = (data && data.options && data.options.pageData)
                                   ? data.options.pageData
                                   : null;
         });
      </script>

   </head>
   <body>
      <div data-role="page" data-theme="c" id="page1">
         <div data-role="content">
            <p>Page 1</p>
            <a href ="#page2?id=a" data-transition="flip" data-role="button">Page 2a</a>
            <a href ="#page2?id=b" data-transition="flip" data-role="button">Page 2b</a>
         </div>
      </div>

      <div data-role="page" data-theme="a" id="page2">
         <div data-role="content">
            <p id="page_text"></p>
            <a href ="#page1" data-transition="flip" data-role="button">Page1</a>
         </div>
      </div>

   </body>
</html>

The problem is with appended url variables with ajax navigation. JQM uses the appended variables with its own navigation. According to the docs, either lose the ajax navigation, or lose the variables. Breaking it up into several pages with rel="external" would also fix the problem if a web site (not app).

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