I see a lot of sites like gitHub , changing its html content and URL
without refreshing the pages.
I find one possible way to do this at HTML Histroy API
.
Here is the code.
HTML
<div class="container">
<div class="row">
<ul class="nav navbar-nav">
<li><a href="home.html" class="historyAPI">Home</a></li>
<li><a href="about.html" class="historyAPI">About</a></li>
<li><a href="contact.html" class="historyAPI">Contact</a></li>
</ul>
</div>
<div class="row">
<div class="col-md-6">
<div class="well">
Click on Links above to see history API usage using <code>pushState</code> method.
</div>
</div>
<div class="row">
<div class="jumbotron" id="contentHolder">
<h1>Home!</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
</div>
</div>
</div>
home.html
This is home page
about.html
This is about page
contact.html
That one is content page
JAVASCRIPT
<script type="text/javascript">
jQuery('document').ready(function(){
jQuery('.historyAPI').on('click', function(e){
e.preventDefault();
var href = $(this).attr('href');
getContent(href, true);
jQuery('.historyAPI').removeClass('active');
$(this).addClass('active');
});
});
window.addEventListener("popstate", function(e) {
getContent(location.pathname, false);
});
function getContent(url, addEntry) {
$.get(url)
.done(function( data ) {
$('#contentHolder').html(data);
if(addEntry == true) {
history.pushState(null, null, url);
}
});
}
</script>
This code works fine even if you return or go to the browser.
But the problem is that when you refresh the page, it shows only the updated file. For example, if you upgrade about.html
, then displays only the following: This is the about page
.
gitHub . gitHub
, , , .
?
...