jquery - Load content with Javascript, but still retain a unique link to specific content pages -


i'm web novice, i'll start expressing problem in case there's better solution way i'm trying achieve it.

i've changed site's content loaded dynamically through jquery load() function whole page isn't requested every time unique document content changes. however, want site still have way of taking users specific piece of content if visited direct address of document via url (so users can linked specific pages of content).

i implemented url parameters e.g. "&cat=1&page=2" , got them using jquery , loaded correct file #content area. when user clicks link in navigation, loads relevant content , adds parameters of page url example gave.

this code:

//adding location params url when navigation link clicked $("#innernavbar > ul > li > a").on('click', function(){     var cat = $(this).parent().parent().attr('id');     var page = $(this).attr('name');     var path = "categories/"+cat+"/"+page+".php";     window.location = "#?cat="+cat+"&page="+page;     $("#content").load(path); });  //get url params , load correct page var path = "categories/"; var cat = $.geturlvar('cat'); //external code in geturlparams.js var page = $.geturlvar('page'); if (cat){     if (page){         path = "categories/"+cat+"/"+page+".php";     } else {         path = "categories/"+cat+"/index.php";     } } else {     path = "categories/pages/index.php"; } $("#content").load(path); 

the specific code i'm having problems this:

window.location = "#?cat="+cat+"&page="+page; 

i'm using code add params url without reloading page (with # tag), however, # mean page won't reloaded if user on page "#?cat=things&page=stuff" in url.

i may have over-complicated this, long story short, there way can add params url without sending http request/reloading page , without using # @ start?

and again, if there's solution general problem welcome :)

if don't want start going down road of using single-page application framework, @alejandro gonzález mentioned, checking hashchange event on window , calling function best bet. like:

function processparams() {   var params = window.location.hash;   // params }  $(window).on('hashchange', processparams); 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -