JavaScript;从其他框架内访问框架集框架

发布于 2024-08-09 03:40:09 字数 456 浏览 4 评论 0原文

我有一个使用框架集的系统,在框架集框架内有一些调用,例如;

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懒猫 2024-08-16 03:40:09

您正在使用 jQuery 集覆盖 top.frame1 中的值,该值与默认对象(窗口对象)不同,这就是您收到“未定义”错误的原因 - a jQuery set 没有 document 属性。

如果您想在不更改对 top.frame1 的所有引用的情况下修复此问题,那么您有多种选择。假设 #containerframe 是您的 iframe,我认为这将

在您的父级页面中

frame1 = self.frames.containerframe.frames.frame1;

起作用编辑

frames 集合基于 name 属性工作,因此确保你的 iframe 看起来像这样

<iframe id="containerframe" name="containerframe" />

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 a document 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 work

In your parent-most page

frame1 = self.frames.containerframe.frames.frame1;

EDIT

The frames collection works off of name attributes, so make sure your iframe looks like this

<iframe id="containerframe" name="containerframe" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文