JavaScript;从其他框架内访问框架集框架
我有一个使用框架集的系统,在框架集框架内有一些调用,例如;
top.frame1.location = "newlocation";
但是
top.frame2.afunction();
我正在更新系统,现在框架集驻留在 iframe 内,因此显然所有 top.frame.whatever 调用都不再起作用。现在我正在尝试找到一个不涉及更改“顶部”的解决方案。在运行各种功能的大量页面中。
我尝试在最上面的页面做这样的事情;
frame1 = $('#containerframe').contents().find('#frame1');
但这似乎不起作用,它只是说在尝试访问文档时 top.frame1.document 未定义。
任何建议都会很酷:)
I have a system in place which uses a frameset, within the frameset frames there are some calls like;
top.frame1.location = "newlocation";
and
top.frame2.afunction();
However I am updating the system, and now the frameset resides inside an iframe, so obviously all of the top.frame.whatever calls no longer work. Now I'm trying to find a solution which doesn't involve changing the "top." in the ton of pages that run various functions.
I've tried in the top most page doing something like this;
frame1 = $('#containerframe').contents().find('#frame1');
But that doesn't seem to work, it just says top.frame1.document is undefined when trying to access the document.
Any suggestions would be cool :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用 jQuery 集覆盖
top.frame1
中的值,该值与默认对象(窗口对象)不同,这就是您收到“未定义”错误的原因 - a jQuery set 没有document
属性。如果您想在不更改对 top.frame1 的所有引用的情况下修复此问题,那么您有多种选择。假设
#containerframe
是您的 iframe,我认为这将在您的父级页面中
起作用编辑
frames
集合基于name
属性工作,因此确保你的 iframe 看起来像这样You are overwriting the value in
top.frame1
with a jQuery set, which is NOT the same object as the default (which is a window object) which is why you are getting the "undefined" error - a jQuery set doesn't have adocument
property.If you want to fix this without changing all your references to top.frame1, then you have a couple choices. Assuming
#containerframe
is your iframe, I think this will workIn your parent-most page
EDIT
The
frames
collection works off ofname
attributes, so make sure your iframe looks like this