admin管理员组文章数量:1252793
I am using History.js in my webpage.It's working fine,but when user click the breadcrumb on the page es to the first page directly,i.e.,without clicking browser back button, the History.js stack is not cleared and noe pressing back button on first page doesn't work properly.
is there a way I can clear the History.js stack.
In Html5 history api I would do history.go(-(history.length - 1));
but when using History.js History.length
gives me 0 always,even if I followed breadcrumb and skipped some of the back button clicks.
I am using History.js in my webpage.It's working fine,but when user click the breadcrumb on the page es to the first page directly,i.e.,without clicking browser back button, the History.js stack is not cleared and noe pressing back button on first page doesn't work properly.
is there a way I can clear the History.js stack.
In Html5 history api I would do history.go(-(history.length - 1));
but when using History.js History.length
gives me 0 always,even if I followed breadcrumb and skipped some of the back button clicks.
4 Answers
Reset to default 8 +50There is no way to clear the session history or to disable the back/forward navigation from unprivileged code. The closest available solution is the location.replace() method, which replaces the current item of the session history with the provided URL. Mozilla Source
There is a solution like this :
var Backlen=history.length;
history.go(-Backlen); // Return at the beginning
window.location.replace("page url to redirect");
Source
Donovan's answer is great but does not work in my case. The backlength index is one too high and therefore, the mand history.go(-Backlen) will be ignored.
This solution works in my case:
var backlen = history.length - 1;
history.go(-backlen); // Return at the beginning
history.replaceState({}, null, 'your relative url');
I don't know the direct answer, but you could try window.location.replace(url);
.
To quote another post: after using replace() the current page will not be saved in session history, meaning the user won't be able to use the Back button to navigate to it In Javascript, how do I "clear" the back (history -1)?
This is the History.js equivalent.
var urlPath = "index.html";
var response = { "html": htmlpage.toString() };
var currentIndex = History.getCurrentIndex();
// Return at the beginning
if( currentIndex > 0 )
History.go( -currentIndex );
//pushState will clear forward history
History.pushState( response , null, urlPath );
本文标签: javascriptclear History stack of HistoryjsStack Overflow
版权声明:本文标题:javascript - clear History stack of History.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740319986a2261058.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论