使用JavaScript来监视框架的变化
我的服务器上有一个框架集,它托管位于同一域的顶部框架主菜单和一个底部框架,其内容有时位于同一域,有时位于远程域。
我想监视底部框架以查看它是否发生变化,如果确实发生变化,它会转到什么 URL。有没有办法使用 JavaScript 来做到这一点?
I have a frameset on my server which hosts a top frame main menu which is on the same domain, and a bottom frame which the content is sometimes on the same domain and sometimes on a remote domain.
I would like to monitor the bottom frame to see if it changes, and if it does change, what URL it went to. Is there a way to do this using JavaScript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您可以控制来自您的域的内容,您应该能够检测到用户何时离开您的域。您可以通过侦听单击事件来捕获正常的链接导航,并添加额外的代码以通知导航到用户可能离开页面的任何其他方式。
然而,一旦框架显示来自远程域的内容,如果没有内容本身的合作,您将无法从中获取任何信息(即使这样,也涉及令人讨厌的跨域通信黑客)。指向远程域的框架不会向您的页面报告有关其自身的任何信息,甚至不会报告当前的 URL。
If you have control over the content coming from your domain, you should be able to detect when the user is leaving your domain. You can catch normal link navigation by listening to click events, and add extra code to notify of navigation to any other ways the user may leave the page.
Once the frame is showing content from a remote domain, though, you won't be able to get any information out of it without co-operation from the content itself (which, even then, involves nasty cross-domain communication hacks). A frame pointing to a remote domain will not report any information about itself to your page, not even the current URL.
您应该能够绑定到 iframe 上的
load
并使用它。You should be able to bind to the
load
on the iframe and work with that.