在覆盖层而不是主页中打开 URI
在我的页面上,覆盖层是通过使用 jQuery 插入内容然后淡入来加载的。
我想要做的是:
当您单击打开覆盖层时,会加载一个 URI(例如 news/12,其中 news 是类别, 12 是要加载的项目的 ID)。 除此之外,不应将其加载到正文中,而应将其加载到覆盖层中。
换句话说,我想实现像在 Facebook 上一样的效果,你打开一个覆盖层,网址发生变化,但主页保持不变。
我猜你需要 ajax 来做到这一点,但我不知道如何做到这一点。
谢谢
On my page, overlays are loaded by inserting their content with jQuery and then fading in.
What I want to do is this:
When you click to open an overlay, an URI is loaded (e.g. news/12, where news is the category and 12 is the id of the item to load).
Except, instead of loading it in body, it should be loaded in the overlay.
In other words, I want to achieve something like on facebook, where you open an overlay, the url changes, but the main page stays the same.
I'm guessing you need ajax for this, but I have no idea whatsoever how to do it.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来您想使用新的
history.pushState(...)
和history.popState(...)
浏览器 API。这篇文章可能会帮助您:更改浏览器中的 URL,而不使用 JavaScript 加载新页面
It sounds like you want to use the new
history.pushState(...)
andhistory.popState(...)
browser API.This SO post might help you out: Change the URL in the browser without loading the new page using JavaScript
使用四四方方。请参阅http://onehackoranother.com/projects/jquery/boxy/tests.html#
AJAX 示例:
参见这个问题:Ajax - 如何按内容更改 URL
Use Boxy. See http://onehackoranother.com/projects/jquery/boxy/tests.html#
AJAX example:
See this question: Ajax - How to change URL by content
感谢Lethargy的回答,我解决了这个问题。
.pushState()
正是我需要让 URL 反映使用 jQuery 动态创建的覆盖层的内容。经过一些调整和调试,我设法让它一切正常。
现在我的覆盖层(或弹出窗口、对话框等)已准备好搜索引擎,并且用户可以复制粘贴网址:)
I solved it thanks to Lethargy's answer.
.pushState()
is exactly what I need to have the URL reflect the contents of the overlay that is dynamically created with jQuery.With some tweaking around and debugging I managed to get it all working.
Now my overlays (or popups, dialogs, whatever) are search engine ready, and the url is copy-pastable for users :)