Refresh html loaded on div using jQuery? -


i making website , use jquery load html pages inside divs, main index html remains intact way. problem if user browsing html loads inside div , tries refresh browser(f5) content gets "lost" since it's 1 page(index.html).

is there way around this?

<a onclick='$("#content").load("page1.html");'>page1</a>  <div id="content"></div> 

there's 2 solutions that. if user clicks link, add hashtag url. example:

<a onclick='$("#content").load("page1.html"); window.location.hash = "page1.html";'>page1</a>  

then, in jquery, check hashtag when user visits site:

$(function() {     if (window.location.hash.length) {         var hash = window.location.hash.replace('#', '');          $("#content").load(hash);     } }); 

secondly, use cookies think hash way works fine, :)


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -