I am loading conte开发者_运维问答nt into a div, and when loaded I want to change the page's URL to reflect the loaded content. I.E. parent page - http://www.example.com/foo - when content is loaded http://www.example.com/foo#content-1
This code is appending it with "#undefined"
...
var href = $(this).attr('href');
$("#content").load(href, function() {
window.location.hash = (this).hash;
});
... I need to target the loaded content's id or url? I would guess url
thanks!
If you want to do that for browser history:
try this plugin: http://benalman.com/projects/jquery-bbq-plugin/
Here is the sample: http://benalman.com/code/projects/jquery-bbq/examples/fragment-basic
on line 4, you are using (this).hash instead of $(this).hash
精彩评论