I'm working on this website to get it responsive, which is a static HTML website which uses some JavaScript to load index.html
on every page.
The problem is that the JavaScript code puts a #
before every link. When you click a link somewhere halfway a page, it will open the new page also somewhere halfway (same scroll position as the link was on the old page).
How can I make the new page always open at the top of the page?
The JavaScript file contains the following script (which is gibberish to me...)
var ScriptJS = true;var lastLocation = document.location.href;$(document).ready(function () {if (!$('#ajax').length) { // Check if index.html was loaded. If not, navigate to index.html and load the hash part with ajax. document.location = document.location.href.substring(0, document.location.href.lastIndexOf('/') + 1) +"#"+document.location.href.substr(document.location.href.lastIndexOf('/') + 1); }if (window.location.hash) // Check if the page is being loaded with a '#'. Load the file. $('#ajax').load(window.location.hash.substr(1));});$(document).on("click", "a:not(.regular)", function (e) {var url = this.href;if (url.indexOf("https") != -1 || url.indexOf('.html') == -1) // External link or picture return;e.preventDefault();$('#ajax').load(url, function () { var pagename = url.substr(url.lastIndexOf('/') + 1); lastLocation = document.location.href.replace(window.location.hash, "") +'#'+ pagename; document.location.href = '#'+ pagename;});});window.onpopstate = function (event) {if (lastLocation != document.location.href) location.reload();else return;};