在IE9中使用history.pushstate [英] Using history.pushstate in IE9
问题描述
问题是,当使用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屋!