Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
558 views
in Technique[技术] by (71.8m points)

javascript - Using history.pushstate in IE9

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...