按下返回按钮时哈希使用问题. [英] Hash use problem when pressing back button.

查看:84
本文介绍了按下返回按钮时哈希使用问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现哈希以使用后退按钮,并在使用AJAX的Web应用程序中保留历史记录.

当我按回车键时,哈希值正确更改,但该页面未按原样显示,并且不保留浏览历史记录以返回上一页,这就像上次访问一样.

我正在使用以下代码,有人可以帮助我,或者告诉我是否遗漏了什么?

在"onhashchange"中收费相应的页面

I''m trying to implement the hash to use the back button and keep a history in my web application which uses AJAX.

When I press back, the hash is changed correctly but the page is not displayed as it should and does not keep the browsing history as to return to the previous page, this is like last accessed.

I''m using the following code, someone could help me, or tell me if I''m missing something?

In "onhashchange" charge corresponding page

     $ (document). ready (function () {
         window.onhashchange = function () {
             loadHash (window.location.hash);
         }
       
     });

     loadHash function (stHash) {
             alert (stHash);
             stUrl var = "";
             stParam var = "";
             if (stHash.indexOf ('/')> = 0) {
                 stHash.substring stUrl = (1, stHash.indexOf ('/'));
                 stParam = stHash.substring (stHash.indexOf ('/') + 1)
                 Goto (stUrl +. ​​"aspx?" + stParam);
             Else {}
                 stUrl = stHash;
                 Goto (stUrl +. ​​"aspx");
             }
      
     }



在"changeHas"中,更改哈希.

   



In "changeHas",I change the hash.

    

 changeHash function (stHash) {
         isChangeHash = false;
         window.location.hash = stHash;
     }


谢谢... ...


Thank you ...

推荐答案

(文档).准备就绪(功能(){ 窗口 .onhashchange = 功能(){ loadHash(窗口.位置 .hash); } }); loadHash 函数(stHash){ 警报(stHash); stUrl var = " ; stParam var = " ; 如果(stHash.indexOf(' /')> = 0 ){ stHash.substring stUrl =( 1 ,stHash.indexOf(' /')); stParam = stHash.substring(stHash.indexOf(' /')+ " + stParam); 别的 {} stUrl = stHash; 转到(stUrl +." ); } }
(document). ready (function () {          window.onhashchange = function () {              loadHash (window.location.hash);          }              });      loadHash function (stHash) {              alert (stHash);              stUrl var = "";              stParam var = "";              if (stHash.indexOf ('/')> = 0) {                  stHash.substring stUrl = (1, stHash.indexOf ('/'));                  stParam = stHash.substring (stHash.indexOf ('/') + 1)                  Goto (stUrl +. ​​"aspx?" + stParam);              Else {}                  stUrl = stHash;                  Goto (stUrl +. ​​"aspx");              }             }



在"changeHas"中,更改哈希.

   



In "changeHas",I change the hash.

    

 changeHash function (stHash) {
         isChangeHash = false;
         window.location.hash = stHash;
     }


谢谢...


Thank you ...


这篇关于按下返回按钮时哈希使用问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆