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

serjas’s picture

Status: Active » Postponed (maintainer needs more info)

It 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?

rballou’s picture

This is probably an edge case, but in general it's just a coding issue to watch for:

  1. The variable title is defined within the if statement
  2. When there are no matches, the if statement won't execute so the title variable will not get defined
  3. Later in the code, the title variable 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 title variable 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.

serjas’s picture

Status: Postponed (maintainer needs more info) » Patch (to be ported)