回到 iframe 的历史记录,但更改主窗口的地址
我已经找到了操纵除我需要的之外的所有内容的解决方案。这是场景
就像在 GMail 中一样 - 主要内容呈现在 iframe 中。单击主页上的链接会指向 iframe。这效果很好,而且无缝。 此时,如果我单击浏览器上的“返回”,iframe 将返回。这很好,因为涉及缓存并且页面不会重新下载。
添加修改哈希的通用逻辑会破坏一切。现在,当您回击时,浏览器会更改 has,但不会更改 iframe 历史记录。我尝试访问该特定 iframe 的历史记录 frames['myiframe'].history.back()
但这仍然会更改哈希值而不更改 iframe 源。
我发现了一个偷偷摸摸的 history.replaceState(temp, '', iframelocation)
并且在单击链接时它可以无缝工作,但向后看它实际上会尝试在主窗口中加载 iframe 位置。
我不知所措。我知道 GMail 不会在您每次回退或转发时请求所有信息。那么它是如何做到的呢?它是否使用多个 iframe,并更改哪一个可见?
谢谢!
聚苯乙烯 测试了一个简单的情况:创建一个 iframe,并通过一些 a 更改链接 现在通过
location.href = 'something'
更改哈希值 到目前为止一切顺利。现在,如果您明确告诉 iframe 返回历史记录 - 它不会 frames['iframe'].contentWindow.history.back()
I've found solutions for manipulating everything except what I need. Here's the scenario
Just like in GMail - main content is presented in an iframe. Clicking links on the main page targets the iframe. This works well, and seamless.
At this point if I click "Back" on the browser -- the iframe will go back. This is good because cache is involved and the page doesn't re-download.
Adding a common logic of modifying the hash breaks everything. Now when you hit back the browser changes the has, but does NOT change the iframe history. I've tried accessing the history of that particular iframeframes['myiframe'].history.back()
but that still changes the hash without changing the iframe source.
I've found a sneaky history.replaceState(temp, '', iframelocation)
and this works seamless when clicking links, but going backwards it actually tries to load the iframe location in the main window.
I'm at a loss. I know GMail does not request all information every time you hit back or forward. So how does it do it? Does it use multiple iframes, and change which one is visible?
Thanks!
P.S.
Tested a simple situation: create an iframe, and change a link via some <a href="child" target="iframe">a
Now change the hash via location.href = 'something'
So far so good. Now if you specifically tell the iframe to go back in history - it will notframes['iframe'].contentWindow.history.back()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信 Gmail 使用 AJAX 请求来填充 Div 层。您应该考虑使用 JQuery 动态加载数据。还有一个 jquery 历史记录插件,可以让您无缝地移动和移动。 http://github.com/tkyk/jquery-history-plugin
Gmail uses AJAX requests to populate Div Layers i believe. You should look into using JQuery to dynamically load data. There is also a jquery history plugin which works to allow you to move and forth seamlessly. http://github.com/tkyk/jquery-history-plugin
这不是一个直接的答案,但如果您浏览一下 jQuery BBQ @ http://github.com/cowboy/jquery-bbq/raw/master/jquery.ba-bbq.js
它覆盖后退/前进按钮并保留 in - 浏览器历史记录,如果有的话。
This is not a direct answer but it might be useful if you glance at the source code of jQuery BBQ @ http://github.com/cowboy/jquery-bbq/raw/master/jquery.ba-bbq.js
It overrides the back/forward buttons and keeps an in-browser history, if that's any use.
我还没有找到一种方法让浏览器负责使用历史记录中的缓存。
我的最终解决方案是使用 jquery 的历史记录插件和 div 对象的 JavaScript 哈希数组。
快速检查该值是否不为空 - 并用 div 替换屏幕中心。到目前为止,它的工作方式就像一个魅力,除了如果您单击已加载的链接,哈希值不会改变,因此检测预期的刷新(通过单击您已打开的视图的链接)更加困难。
祝你好运!
I've not found a way to have the browser be responsible for using the cache in the history.
My final solution was using jquery's history plugin, and a javascript hash-array of div objects.
a quick check if that value is not null - and replacing center of the screen with the div. So far works like a charm, with the exception that the hash value does not change if you click a link that's already loaded, so detecting an intended refresh (by clicking the link of a view that you're already on) is harder.
Good luck!