Back to top links in Mediawiki/Wikipedia

spiros

  • Administrator
  • Hero Member
  • *****
    • Posts: 824887
    • Gender:Male
  • point d’amour
Back to top links in Mediawiki/Wikipedia

Back to top and search suggestions on Project:Support desk
Wikipedia:Back to top - Wikipedia

Or, if you have Edit section disabled you can use mw-headline to trigger the event (add in Common.js):

Code: [Select]
( function () {
var elems = document.getElementsByClassName('mw-headline'); // *** NOTE: ClassName may need to be 'mw-editsection' instead
for (i = 0; i < elems.length; i++) {
var span = document.createElement('span');
span.classList.add('ttop');
var link = document.createElement('a');
link.href = '#top';
link.appendChild(document.createTextNode('back to top'));
span.appendChild(document.createTextNode('['));
span.appendChild(link);
span.appendChild(document.createTextNode('] '));
elems[i].insertBefore(span, elems[i].firstChild);
}
});

Since I also added a style, you need to add the following in Common.css to have the text in a small size and right-aligned.

Code: [Select]
span.ttop {
    float: right;
    font-size: small;
}
« Last Edit: 04 Oct, 2021, 18:56:52 by spiros »


 

Search Tools