Pinterest like ajax loading

2019-05-30 14:59发布

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条回答
唯我独甜
2楼-- · 2019-05-30 15:47

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('', '', '/')

查看更多
登录 后发表回答