javascript - Pageshow not triggered after changepage -


i using jquery mobile , redirect browser page, after user clicked on button on home. wrote:

$.mobile.changepage("album-search-results.html",{                data:{area:searcharea, value:searchvalue},                transition: "pop"            }); 

and works fine, loads correct page , puts right values on url. unfortunately pageshow event not triggered:

    <!doctype html> <html> <head>       <meta name="viewport" content="width=device-width, initial-scale=1">      <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>     <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>     <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" /> </head>  <body>     <div data-role = "page" data-theme = "d" id = "searchresults">          <div data-role = "header">             <h1>aggregator</h1>         </div>          <div data-role = "content">          </div>     </div>      <script type="text/javascript">         $("#searchresults").on("pageshow",function(event, ui){             console.log(ui.prevpage);          });      </script> </body> </html> 

the console in empty when load page previous one. wrong? thanks

solution

solution simple, move script block inside page div. in case script block discarded. change this:

from :

<body>     <div data-role = "page" data-theme = "d" id = "searchresults">          <div data-role = "header">             <h1>aggregator</h1>         </div>          <div data-role = "content">          </div>     </div>      <script type="text/javascript">         $("#searchresults").on("pageshow",function(event, ui){             console.log(ui.prevpage);          });      </script> </body> 

to :

<body>     <div data-role="page" data-theme="d" id="searchresults">         <div data-role = "header">             <h1>aggregator</h1>         </div>         <div data-role = "content">          </div>         <script>             $(document).on("pageshow","#searchresults",function(event, ui){                 console.log(ui.prevpage);             });         </script>            </div> </body> 

example:

index.html

<!doctype html> <html>     <head>         <title>jqm complex demo</title>         <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densitydpi=device-dpi"/>         <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />         <script src="http://www.dragan-gaic.info/js/jquery-1.8.2.min.js"></script>               <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>             <script>             $(document).on('click', '#change-page', function(){                        $.mobile.changepage("album-search-results.html",{                     data:{area:"asda", value:"1"},                     transition: "pop"                 });             });                          </script>     </head>     <body>         <div data-role="page" id="index">             <div data-theme="a" data-role="header">                 <h3>                     first page                 </h3>                 <a href="#second" class="ui-btn-right">next</a>             </div>              <div data-role="content">                 <a data-role="button" id="change-page">change page</a>             </div>              <div data-theme="a" data-role="footer" data-position="fixed">              </div>         </div>         </body> </html>    

album-search-results.html

<!doctype html> <html> <head>     <meta name="viewport" content="width=device-width, initial-scale=1">     <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>     <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>     <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" /> </head>     <body>         <div data-role="page" data-theme="d" id="searchresults">             <div data-role = "header">                 <h1>aggregator</h1>             </div>             <div data-role = "content">              </div>             <script>                 $(document).on("pageshow","#searchresults",function(event, ui){                     console.log(ui.prevpage);                 });             </script>                </div>     </body> </html> 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -