添加#!到jQuery地址

时间:2011-04-19 00:34:24

标签: ajax jquery hash web-crawler

我正在使用jquery地址插件,现在我的网址就像http://localhost:3000/#/users/1/。我希望它根据http://code.google.com/web/ajaxcrawling/index.html的指南使用#!而不是#

这是我的JS:

$('.likable').find('a').click(function(e) {
        $.address.value($(this).attr('href').replace(/^#/, '').replace('http://'+document.domain,''));
        e.preventDefault();
    });

    $('.ui-show').find('.close').live('click', function(e) {
    history.back();
    e.preventDefault();
  });

  // Setup jQuery Address Listener
    $.address.init(function(event) {

        if ($.address.baseURL() != 'http://' + document.domain) {
            if (location.href.indexOf('#') < 0) {
                // URL has no hash value and is a permalink, e.g. /about/
                // Change address value to that of permalink
                var fullpath = location.href.split('/',4);
                $.address.value(fullpath[3] + '/');
            }
        }

    }).change(function(event) {

        if (event.value != '/') {
      $.get($.address.value(),function(data) {
        // Insert new content
        });
        } else {
            // Remove new content
        }

    });

如何使用#!代替#

2 个答案:

答案 0 :(得分:1)

$.address.crawlable(true);

在你的初始化事件中使用它会自动使所有#成为#!,我在$(document).ready事件中加载了我的<{p}

我希望这可以帮助其他人解决同样的问题

答案 1 :(得分:0)

#的实例替换为#!