The code that checks for the title in the returned AJAX data may result in a JS error. Attached is a patch to help with that, but it does set it to a blank title if one is not found. Not sure on the best thing to do as the default?
// get title of loaded content.
var matches = data.match("<title>(.*?)</title>");
if (matches) {
// -- NOTE --
// Title is defined here, within the if statement
// -- END NOTE --
// Decode any HTML entities.
var title = $('<div/>').html(matches[1]).text();
// Since title is not changing with window.history.pushState(),
// manually change title. Possible bug with browsers.
document.title = title;
}
// store current url.
window.history.replaceState({page : 0} , document.title, window.location.href);
// -- NOTE --
// Title is used here, outside of if statement
// -- END NOTE --
// Change url.
window.history.pushState({page : 1} , title, url);
Comments
Comment #1
serjas commentedIt wont give any error as its checking
if (matches) {i dont find anything new in this patch, can you please explain which part you modified?
Comment #2
rballou commentedThis is probably an edge case, but in general it's just a coding issue to watch for:
titleis defined within the if statementtitlevariable will not get definedtitlevariable is used and if there were no title matches, we'll get a JS error because the variable was never created.The patch moves the definition of the
titlevariable outside of the if statement, giving it a default value of an empty string. That's the one bit I'm not sure about: if there's no title, what should the default be? I'm really unsure that there wouldn't be a title so maybe it's not worth fretting over the default title value.Comment #3
serjas commented