【问题标题】:Adding #! to jQuery Address添加#!到 jQuery 地址
【发布时间】:2011-04-19 00:34:24
【问题描述】:

我正在使用 jquery 地址插件,现在我的 URL 类似于 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
        }

    });

如何使用#! 而不是#

【问题讨论】:

    标签: ajax jquery hash web-crawler


    【解决方案1】:
    $.address.crawlable(true);
    

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

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

    【讨论】:

      【解决方案2】:

      # 的实例替换为#!

      【讨论】:

        猜你喜欢
        • 2011-10-29
        • 2020-08-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-14
        • 1970-01-01
        • 2014-09-01
        相关资源
        最近更新 更多