在IE9中使用history.pushstate [英] Using history.pushstate in IE9

查看:765
本文介绍了在IE9中使用history.pushstate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于window.history.pushState不适用于IE9等HTML 4浏览器,因此我查找了history.js,它是一个模拟pushState行为的jQuery库。



问题是,当使用pushState时,url的结尾是重复的



例如,

  History.pushState(null,null,window.location.pathname +'?page = 1'); 

返回,

http://www.development.com/test.html#test.html?page=1



我如何避免这个问题?

更新(2012/1/22),对于赏金的问题:

  if(pageNo == 1){
//window.history.pushState({\"html\":currURL,\"pageTitle:''}, ,window.location.pathname +'?page = 1');仅适用于chrome和FX
//History.replaceState(null,null,'')
//History.pushState(null,null,'?issue='+ currPageIssueNo +'& page = 1 );
}
else if(pageNo!= 1 || pageNo == 1&& linkPageNo> 1){
History.pushState(null,null,'?issue ='+ currPageIssueNo +'& page ='+ pageNo);
//window.history.pushState({\"html\":currURL,\"pageTitle:''},,newURL);对于chrome和FX只有
}

我仍然遇到问题,如果是第一页

  http://localhost/development/flipV5.html?issue = 20121220& page = 1 

当我在IE9的第二页时,它有url:

  http://localhost/development/flipV5.html?issue = 20121220& page = 1#flipV5.html?issue = 20121220& page = 2 

我想达到的是

  http://localhost/development/flipV5.html?issue = 20121220& page = 2 

如果HTML 4浏览器是不可能的,请至少实现

  http://localhost/development/flipV5.html/# ?问题= 20121220& page = 2 

感谢您的帮助

解决方案

您的代码完全符合您的预期。

  window.loc ation.pathname +'?page = 1'

打印出位置路径名( test.html ),并附加?page = 1



删除 window.location.pathname ,它应该可以工作。


Since window.history.pushState is not aviliable for HTML 4 browsers like IE9 , I have looked for history.js, a jQuery library that simulates the pushState behavior.

The problem is , when using pushState, the end of the url is duplicated

For example,

History.pushState(null,null,window.location.pathname + '?page=1');

returns,

http://www.development.com/test.html#test.html?page=1

How do I avoid this problem? Thank you kindly.

Update (On 2012 / 1 /22) , Question for bounty:

                if (pageNo == 1){
                    //window.history.pushState({"html":currURL,"pageTitle":''},"", window.location.pathname + '?page=1'); For chrome and FX only
                    //History.replaceState(null,null,'')
                    //History.pushState(null,null,'?issue=' + currPageIssueNo + '&page=1');
                }   
                else if (pageNo != 1 || pageNo == 1 && linkPageNo > 1  ) {
                    History.pushState(null,null,'?issue=' + currPageIssueNo + '&page=' + pageNo);
                    //window.history.pushState({"html":currURL,"pageTitle":''},"", newURL);   For chrome and FX only
                }

I am still encounter the problem , if it is the first page

http://localhost/development/flipV5.html?issue=20121220&page=1

When i go to second page in IE9 , it has url :

http://localhost/development/flipV5.html?issue=20121220&page=1#flipV5.html?issue=20121220&page=2

Which i would like to achieve is

http://localhost/development/flipV5.html?issue=20121220&page=2

If it is impossible for HTML 4 browser, please at least achieve

http://localhost/development/flipV5.html/#?issue=20121220&page=2

thanks for kindly help

解决方案

Your code does exactly what you'd expect it to.

window.location.pathname + '?page=1'

Prints out the location pathname (test.html), and appends ?page=1

Remove window.location.pathname and it should work.

这篇关于在IE9中使用history.pushstate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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