<div id="conteudo">
<div class="header">
<a href="www.google.com.br">ir para pagina1</a>
<a href="www.terra.com.br">ir para pagina2</a>
<a href="www.uol.com.br">ir para pagina3</a>
</div><!-- /header-->
</div><!-- /conteudo-->
<div id="loading">loading .... </div>
CSS
#loading {
display: none;
}
JavaScript
$('.header a').click(function(e) {
e.preventDefault();
$("#loading").show();
href = $(this).attr("href");
loadContent(href);
// HISTORY.PUSHSTATE
console.log(history.pushState('', 'New URL: ' + href, href));
});
function loadContent(url) {
// USES JQUERY TO LOAD THE CONTENT
$.getJSON("/echo/json/", {
cid: url,
format: 'json',
data: {
json: JSON.stringify({
text: 'some text'
})
}
}, function(json) {
// THIS LOOP PUTS ALL THE CONTENT INTO THE RIGHT PLACES
$.each(json, function(key, value) {
$(key).html(value);
});
$("#loading").hide();
});
// THESE TWO LINES JUST MAKE SURE THAT THE NAV BAR REFLECTS THE CURRENT URL
$('li').removeClass('current');
$('a[href="' + url + '"]').parent().addClass('current');
}
// THIS EVENT MAKES SURE THAT THE BACK/FORWARD BUTTONS WORK AS WELL
window.onpopstate = function(event) {
$("#loading").show();
console.log("pathname: " + location.pathname);
loadContent(location.pathname);
};
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.