0

I am trying to create a jQuerymobile app with a Nav Bar with Multiple Pages in single index.html. I am using the template Multi-page template structure

Unfortunately, I cannot get the nav bar to show different pages. Here is my code:

I did also use a script 'pageLoader.js' to force loading the pages. But that does not work either. Here is my pageLoader.js:

 <!doctype html>
<html>
    <head>
        <title>My Page</title>
        <!--https://jquerymobile.com/download/-->
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
    </head>
    <body>

        <!--POST page 1-->

        <div data-role="page" id="postPage">
            <div data-role="header">
                <h1>I'm a header</h1>
                    <div data-role="navbar">
                        <ul>
                            <li><a href="#postPage">POST</a></li>
                            <li><a href="#getPage">GET</a></li>
                                    <li><a href="#putPage">PUT</a></li>
                        <li><a href="#deletePage">DELETE</a></li>
                    </ul>
                        </div><!-- /navbar -->
            </div><!-- /header -->

            <div role="main" class="ui-content">


                <label for="key">key:</label>
                 <input type="text" name="key" id="key" placeholder="enter your key" value="" data-clear-btn="true">

                <label for="value">value:</label>
                 <input type="text" name="value" id="value" placeholder="enter your value" value="" data-clear-btn="true">

                <button onclick="saveValue()"> Store Key</button>
                <p id="status">Status: No Activity</p>

            </div><!-- /content -->

            <div data-role="footer">
                <h4>My Footer</h4>
            </div><!-- /footer -->

            <!--get Page 2-->

            <div data-role="page" id ='getPage'>

                <div data-role="header">
                    <h1>I'm a header</h1>
                        <div data-role="navbar">
                                <ul>
                                        <li><a href="#postPage">POST</a></li>
                                        <li><a href="#getPage">GET</a></li>
                                        <li><a href="#putPage">PUT</a></li>
                            <li><a href="#deletePage">DELETE</a></li>
                                </ul>
                            </div><!-- /navbar -->
                </div><!-- /header -->

                <div role="main" class="ui-content">


                    <label for="key">key:</label>
                     <input type="text" name="key" id="key" placeholder="enter your key" value="" data-clear-btn="true">
                    <button onclick ="getValue()"> Get Value</button>
                    <p id="status">Status: No Activity</p>

                </div><!-- /content -->

                <div data-role="footer">
                    <h4>My Footer</h4>
                </div><!-- /footer -->


            </div><!-- /page -->
            <script src="scripts/client.js" type="text/javascript"></script>
            <script src="scripts/pageLoader.js" type="text/javascript"></script>
    </body>
</html>

I also tried to use a script to enforce change of pages. I used the pageLoader.js script with following content:

$(document).on("pageshow", function(){
    if($('.ui-page-active').attr('id') === 'postPage'){
        $.mobile.changePage("#postPage");
    } else if ($('.ui-page-active').attr('id') === 'getPage'){
         $.mobile.changePage("#getPage");
    }
});

Any help would be greatly appreciated.

chikitin
  • 762
  • 6
  • 28
  • 2
    My advice, use jQuery Mobile 1.4.5. 1.3.2 is way too old, technically so is 1.4.5. Plus page 2 is inside page 1, which is not correct. – Gajotres Nov 27 '18 at 07:55
  • 2
    If I remember it correctly, shared navigation is working only in 1.4.X jQuery Mobile, however, it was never working as expected so the way around was to add it dynamically: https://stackoverflow.com/questions/11199391/keep-navbar-on-all-pages-with-jquery-mobile – Gajotres Nov 27 '18 at 09:44

0 Answers0