【问题标题】:URI changes without reload?URI更改而不重新加载?
【发布时间】:2013-07-21 20:26:39
【问题描述】:

他们是如何在主题中完成此功能的,您单击永久链接(眼球)按钮 uri 会发生变化,而没有哈希 (#) 这是如何完成的?是阿贾克斯吗?或者别的什么。

我假设它正在调用页面但没有重新加载?

主题:http://thingslog-theme.tumblr.com/ (点击每个帖子底部的眼球)

我很难过并帮忙?

【问题讨论】:

  • 您正在寻找 HTML5 历史 API。

标签: jquery ajax themes uri tumblr


【解决方案1】:

他们使用这种代码:

$('a').click(function() {
    link = $(this).attr('href')
    history.pushState({}, '', link);
    $('#content').load('/content.php?url='+link)
    return false;
})

history pushstate function 允许您添加和修改浏览器历史记录条目。

【讨论】:

    【解决方案2】:

    我们使用 Backbone + HTML5 pushState 来处理没有哈希的 URI 更改。之所以有效,是因为我们遵循 Tumblr 为所有博客构建其 URL 的方式。

    我们使用 jQuery.load 来处理获取 html 并将其加载到页面中。

    这段代码看起来有点像这样:

    $container.load('http://blog.tumblr.com/post/123 #container', function() {
      var $post = that.$('.overlay-container .post');
      that.view = new App.PostViewFactory.createView($post);
    
      that.view.on('close', function() {
        window.history.back();
      });
    });
    

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2014-09-08
      • 1970-01-01
      • 1970-01-01
      • 2013-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-28
      • 1970-01-01
      相关资源
      最近更新 更多