iOS iframe pageshow 事件未触发
在页面导航离开然后返回后,我似乎很难尝试在 iframe 中重新实例化任何 J/S 事件侦听器。这似乎只在 iOS (iPhone 5.x) 中不起作用,并且在其他 WebKit (即 Linux Chrome) 中完美工作
我已在 http://manticore.2y.net/fvt/tt.html。
文档结构非常简单,没有涉及J/S框架。
主文档实际上是一个加载 iframe 的空壳,iframe 的内容有 javascript。示例 javascript 将事件侦听器绑定到图像,下面的文本上也有一个事件侦听器,通过 tag 属性指定。现在,当单击页面上的链接时,会显示另一个页面(该链接是目标 _top。对于 _self,一切正常,即 pageshow 正常触发)。当用户导航回上一页时,iframe 内文档的所有事件看起来都死了,并且此时没有 pageshow 事件被传递。
因此,如果您在 iPhone 上打开上面的链接并单击图像,您会看到弹出窗口。只要你点击底部的链接,返回原来的页面,点击图片,或者文字,都不会执行任何j/s。
这个问题有什么解决方法吗?特别是考虑到在现实世界中我将无法控制主页,并且主页也将位于不同的域上。我发现的唯一一件事是,如果我设置了 J/S 间隔,当我返回页面时,该东西将恢复滴答作响,并且我可以将其与侦听器结合使用来“卸载”以重新建立我的侦听器(就此而言,我是否保证在卸载侦听器返回后、页面挂起之前不会触发超时)。
I seem to struggle with attempting to re-instantiate any J/S event listeners in an iframe after the page have been navigated away from and then back to. This seem to only not work in iOS (iPhone 5.x), and works perfectly in other WebKit (i.e. Linux Chrome)
I've published the code at http://manticore.2y.net/fvt/tt.html.
The document has a very simple structure, and there are no J/S frameworks involved.
Main document is effectively an empty shell that loads an iframe, the contents of an iframe have javascript. The sample javascript binds event listener to the image, and there is also an event listener on the text below, specified with the tag attribute. Now, when a link is clicked on the page, another page is displayed (the link is target _top. For _self, things work normally, i.e. the pageshow normally fires). When the user navigates back to the previous page, all the events of the document inside the iframe look dead, and no pageshow event is delivered at that time.
So if you open the link above on iPhone and click on the image, you'll see pop up. As long as you follow the link at the bottom, and return back to the original page, clicks on either the image, or the text, will not execute any j/s.
Is there any workaround to this problem? Especially considering that in real world I will have no control over the main page, and the main page will be on a different domain as well. The only thing that I have found is that if I set up a J/S interval, that thing will resume ticking when I go back to the page, and I can use that in conjunction with listener to 'unload' to re-establish my listeners (and for that matter, am I guaranteed that my timeout wouldn't fire after unload listener returns, and before the page is suspended).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论