简体   繁体   中英

jQM - Javascript doesn't work in 'file.html' when use $.mobile.changePage

I'm trying to make transition between two .html files using jQM (just for test):

index.html:

 <script>

  function Go(){
     var url = "go.html?go='123'";
     $.mobile.changePage(url, {transition: "slide"});
  }

 </script>

<body>
   <button onclick='Go();'>Go!</button>
</body>

go.html:

  <script>
$( document ).on("#mainpage", "pageinit", function() {
  // CODE GET URL VARs

   function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,             function(m,key,value) {
    vars[key] = value;
    });
    return vars;
  }

  var go = getUrlVars()['go'];

  alert(go);
});
  </script>

The transition works fine, and i see (in the url browser) the variable ' go ' is there (123).

When the translation finish, the alert doesn't work and i have to refresh the page (F5) to see the alert (' 123 '): JAVASCRIPT IN go.html DOESN'T WORK.

How can i fix this issue?

The scripts you want executed on that page need to be handled on the pageinit or pagechange event in jQm. Go read the scripting section on the jQm docs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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