开发者

Append URL with .load() - loaded content's id or file name

开发者 https://www.devze.com 2023-02-10 16:58 出处:网络
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 h

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号