简体   繁体   中英

Reload the previous page by clicking the back button

My main page look like this:

<body>
    <div id="MainPage" data-role="page">
        <script>
            $("#MainPage").live("pageinit", function () { ... });
        </script>
        ...//I have a map and when I walk to the next page I delete the map.
    </div>
</body>

My next page look like this:

<body>
  <div id="NextPage" data-role="page">
    <script>
      $("#NextPage").live("pageinit", function () {... });
    </script>
 <a data-res="btnBack" data-role="button" data-theme="b" href="MainPage.html"
                data-icon="back" data-iconpos="left" onclick="document.MainPage.reload(true);">
            </a>
    ...//I have a map and when I walk to the Main page I delete the map.
  </div>
</body>

Because I delete the maps I have to reload the main page and it does not work that way, the main page is not recognized as a page and therefore has no reload function.

Can anyone help?

Try to save the web address of the main page when you go from main page to next page.

for example : you use a link or button to traverse from one page to other use this code to save the url of the current page and then send it to other page using querystring or something else.

$(document).ready(function(){
var url =$(location).attr("href");
});

variable 'url' contains the url of main page , now reload function to reload it. as:

 $(document).ready(function(){
 window.reload(url);
 })

To jump to any other page use this code:

$.mobile.changePage("#page", {transition: "none", reloadPage : false});

Set a transition effect if you want one, and set reloadPage true if you want to reload that page.

Use this code to reload current page:

function refreshPage() {
  $.mobile.changePage(
    window.location.href,
    {
      allowSamePageTransition : true,
      transition              : 'none',
      showLoadMsg             : false,
      reloadPage              : true
    }
 );

}

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