【问题标题】:Pinterest like ajax loadingPinterest 喜欢 ajax 加载
【发布时间】:2012-10-14 13:28:57
【问题描述】:

我正在使用 Wordpress 开发一个网站,在该网站上使用 AJAX 加载帖子,同时将 url 更改为帖子的实际永久链接。就像 pinterest 的工作方式一样。 AJAX 加载的内容显示在模式框中。我用

window.history.pushState(stateObj, title, url) 将浏览器的 url 更改为帖子的永久链接。现在我的问题是:

当模态框关闭时,我想转到上一个网址而不重新加载页面。

例如我在主页(http://example.com)上,然后我点击一个帖子,模式框打开,通过 AJAX 获取帖子内容,并且 URL 变为(http://example.com/post1)。当模式框关闭时,我希望 url 返回 (http://example.com) 而无需实际页面重新加载。所以基本上只能到之前的状态。

【问题讨论】:

    标签: wordpress jquery browser-history pinterest


    【解决方案1】:

    所以使用与打开时相同的方式更改 url,但在模式窗口的关闭事件时触发它。

    编辑:要转到根网址,您可以执行 window.history.pushState('', '', '/')

    【讨论】:

    • 试过这种方式,(关闭事件):window.history.pushState('', '', '');因为我想从example.com/post1 转到example.com 但这并不影响url,因为它只意味着没有任何东西可以连接到url。
    • 如果我想从example.com/someotherpage转到example.com/post1,我该如何实现?
    • window.history.pushState('', '', '/post1') 通常从哪里去并不重要
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-20
    • 1970-01-01
    • 2016-04-04
    • 2016-12-31
    • 2015-05-13
    • 1970-01-01
    相关资源
    最近更新 更多