像ajax加载一样的Pinterest [英] Pinterest like ajax loading

查看:118
本文介绍了像ajax加载一样的Pinterest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Wordpress网站,在该网站上,将URL更改为帖子的实际固定链接时,将使用AJAX加载帖子.就像pinterest的工作原理一样. AJAX加载的内容显示在模式框中.我用

I am working on a website with Wordpress where posts are to be loaded with AJAX while changing the url to the actual permalink of the post. Like how pinterest works. The AJAX loaded content is displayed in a modal box. I use

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

window.history.pushState(stateObj, title, url) to change the url of the browser to the post's permalink. Now my problem is:

当模式框关闭时,我想转到上一个URL而不重新加载页面.

When the modal box closes, I want to go to the previous url without reloading the page.

例如我在主页(http://example.com)上,然后单击一个帖子,随即打开一个模态框,其中的内容通过AJAX提取,并且网址变为(http://example.com/post1).当模式框关闭时,我希望该网址返回到(http://example.com),而无需实际重新加载页面.所以基本上只恢复到以前的状态.

e.g. I am on the homepage (http://example.com), then i click a post, modal box opens with the post content fetch through AJAX and the url become (http://example.com/post1). When the modal box closes, I would like the url to go back to (http://example.com) without actual page reload. So basically only to the previous state.

推荐答案

因此,请使用与打开url相同的更改url的方式,但在模态窗口的close事件触发时触发它.

So use same way of changing url like on open but trigger it on close event of modal window.

要转到根URL,您可以执行window.history.pushState('', '', '/')

To go to the root url you can do window.history.pushState('', '', '/')

这篇关于像ajax加载一样的Pinterest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆