Wikipedia:WikiProject User scripts/Scripts/Get Page Name

This is an old revision of this page, as edited by Holly Cheng (talk | contribs) at 16:13, 1 August 2006 (textContent not supported in IE). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Returns the name of the page. For example, if you were browsing the "foo" WP page, getPname() would return "foo".

function getPname() {
  z=document.getElementById("content").childNodes;
  for (var n=0;n<z.length;n++) { 
    if (z[n].className=="firstHeading") {
      var text = z[n].textContent ? z[n].textContent : z[n].innerText;
      return text;
    }
  }
}

/* This code may be problematic when it comes to titles with ampersands, etc, which are stored as ''& amp ;'' in HTML (without the spaces).
  A solution that solves this is the following:
    return document.title.substr(0, document.title.lastIndexOf(' - Wikipedia, the free'));
*/

/* This code was taken from the Show last diff code.

  • /