【问题标题】:Reload the previous page by clicking the back button单击后退按钮重新加载上一页
【发布时间】:2012-11-14 23:19:54
【问题描述】:

我的主页是这样的:

<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>

我的下一页是这样的:

<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>

因为我删除了地图我必须重新加载主页并且它不起作用,所以主页不被识别为页面,因此没有重新加载功能。

谁能帮忙?

【问题讨论】:

  • 主页不被识别为页面,我在控制台窗口中测试过,我认为是这个问题!有谁知道为什么他不被识别为页面?我写: data-role = "page" 到 div

标签: javascript jquery html google-maps jquery-mobile


【解决方案1】:

当你从主页转到下一页时,尽量保存主页的网址。

例如: 您使用链接或按钮从一个页面遍历到另一个页面使用此代码保存当前页面的 url,然后使用查询字符串或其他内容将其发送到其他页面。

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

变量 'url' 包含主页的 url,现在 reload 函数重新加载它。如:

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

【讨论】:

  • Window 对象没有方法'reload',它没有那样工作,所以我在控制台中写了它,并得到以下错误: TypeError: Object [object Window] has no method 'reload'
  • 有效!!通过单击后退按钮,我读取了一个执行命令的函数:window.loction.herf=url;谢谢:]
【解决方案2】:

要跳转到任何其他页面,请使用以下代码:

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

如果需要,请设置过渡效果,如果要重新加载该页面,请设置 reloadPage true。

使用此代码重新加载当前页面:

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

}

【讨论】:

  • $.mobile.changePage("#MainPage", { transition: "none", reloadPage: true });- 刷新当前页面而不是主页面
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-03-30
  • 2013-10-13
  • 2021-01-16
  • 1970-01-01
  • 2018-10-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多