I think this is the answer, I came across this:
https://stackoverflow.com/a/10176315/1063287
"Also ensure that pages loaded in onpopstate() don't try and push use pushState() themselves".
So I kept this:
<script>
$(document).ready(function() {
window.onpopstate = function(event) {
console.log("pathname: "+location.pathname);
loadContent(location.pathname);
};
});
</script>
But removed this from the function:
history.pushState('', 'New URL: '+href, href);
And added it instead to the jQuery triggered on click eg:
$(document).on("click","#main_menu a", function (e) {
href = $(this).attr("href");
loadContent(href);
history.pushState('', 'New URL: '+href, href);
e.preventDefault();
});