AJAX deeplinking with jQuery Address -


i have website has many pages:

for example:

home: http://mywebsite.com/index.html

some page: http://mywebsite.com/categorie/somepage.html

i decided make pages load dynamically ajax without reloading page. decided use jquery address plugin ( http://www.asual.com/jquery/address/docs/ ) in order allow deeplinking , back-forward navigation:

<script type="text/javascript" src="uploads/scripts/jquery.address-1.2rc.min.js"></script> <script type="text/javascript">                 $('a').address(function() {                     return $(this).attr('href').replace(/^#/, '');                 }); </script> 

now, after installing plugin, if go on http://mywebsite.com/index.html (home) , click on some page link, jquery loads http://mywebsite.com/categorie/somepage.html without reloading page , address bar on browser displays: http://mywebsite.com/index.html/#/categorie/somepage.html great!

however, the problem is: if copy dynamically generated url: http://mywebsite.com/index.html/#/categorie/somepage.html web browser address bar, take website index.html page , not "some page" page. also, forward/back buttons don't work correctly, replace address in url bar content stays same.

i suppose need write javascript rule associates dynamic url correct page?

some appreciated. :)

copy paste url address bar working back/next button working.

the # should there make work

anyone know how make #! indexable google?

or #/ same thing?

basically work me on wordpress:

// ajax setup $.ajaxsetup({cache:false, success: function() {  // optional action here }});    // event handlers $.address.init(function(event) {   $('#nav li a').address(function() {   return $(this).attr('href').replace(location.pathname, '');    });  }).bind('externalchange', {}, function(event) {     var post_id; // page id     var nav_id; // nav class     // button      switch (true) {      case (event.value == undefined):            post_id = 2; nav_id = 'home'; break;      case (event.value == "/about"):            post_id = 19; nav_id = 'about'; break;      case (event.value == "/product"):            post_id = 26; nav_id = 'product'; break;      ...etc....       default: post_id = 2; nav_id = 'home';     }      // content loader on back/next button     $("#content-wrap").load("http://www.somesite.com/home/",{id:post_id}); // load content  });      // content loader #nav   $(document).on("click","#nav li a",function(e){                                             var post_id = $(this).attr("id"); // page id       $("#content-wrap").load("http://www.somesite.com/home/",{id:post_id}); // load content      return false; // keep url, no refresh  }); 


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -