Javascript; Accessing frameset frames from within other frames

China☆狼群 提交于 2019-12-02 06:19:18

问题


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 :)


回答1:


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" />


来源:https://stackoverflow.com/questions/1644676/javascript-accessing-frameset-frames-from-within-other-frames

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!