Reputation: 1010
I use history pushstate to load content from an other page and it works great.
I want to implement a close button for loaded pushstate content. But I have some difficulties making it work.
I want to have an empty path name when I click on close button with the title of the website.
Here the close button script:
if (typeof(window.history.pushState) == 'function') {
window.history.pushState(null, refreshdocumenttitle, "");
}
refreshdocumenttitle is the name of the website.
This is not working.
Upvotes: 0
Views: 117
Reputation: 1010
I found the solution:
var pageurl = $(location).attr('href');
if(pageurl.indexOf("http://www.") > -1) {
var nbsuppstart = pageurl.indexOf("www.")+4;
} else {
var nbsuppstart = pageurl.indexOf("//")+2;
}
var nbsuppend = pageurl.indexOf(".com/");
var pagetitle = pageurl.substring(nbsuppstart,nbsuppend);
if (typeof(window.history.pushState) == 'function') {
var stateObj = {
title: pagetitle,
url: '/',
};
window.history.pushState(stateObj,title,'/');
document.title = pagetitle;
}
Upvotes: 2