Pinterest like ajax loading

浪尽此生 提交于 2019-12-08 07:21:29

问题


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) to change the url of the browser to the post's permalink. Now my problem is:

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

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.


回答1:


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

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



来源:https://stackoverflow.com/questions/12882685/pinterest-like-ajax-loading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!