jQuery 将 iframe 中的元素附加到其主体父窗口。
我有 elm.appendTo('#wrap');
其中 elm
是 iframe 内单击图像的 jquery 对象。我想将该图像附加到
中,其中 #wrap
是 iframe 外部页面正文中的 div。所以基本上当我双击 iframe 内的图像时,我希望该图像附加到 iframe 外部的
。正文和 iframe 链接都位于同一域中。I haveelm.appendTo('#wrap');
where elm
is a jquery object of the clicked image inside iframe. I want to append that image to a <div id="wrap">
where #wrap
is a div in the body of the page outside iframe. So basically when i double click on an image inside iframe, i want that image to append to <body>
outside iframe. Both body and iframe link are on the same domain.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
前提是该框架及其父框架位于同一域中。请参阅SOP
Execute either of the following lines from within the iframe (
parent
can be replaced bytop
, if the parent document is in the top window):If you want to grab the element inside the frame, from the context of the parent, use either of the following:
假设
#elm
是您的图像的 ID。frames[0]
指当前文档中的第一帧。如果您在框架上设置了name
属性,则还可以使用frames.frame_name
或frames["frame_name"]
。Final example: Adding a
click
event listener to theelm
JQuery (image) object:Provided that the frame and its parent are at the same domain. See SOP
Execute either of the following lines from within the iframe (
parent
can be replaced bytop
, if the parent document is in the top window):If you want to grab the element inside the frame, from the context of the parent, use either of the following:
Assume
#elm
to be the ID of your image.frames[0]
refers to the first frame within the current document. If you've set aname
attribute on your frame, you can also useframes.frame_name
, orframes["frame_name"]
.Final example: Adding a
click
event listener to theelm
JQuery (image) object:尝试从另一种方式进行处理:从父窗口中找到要附加的元素,然后使用
.append()
并选择 iframe 中的元素。例如:Try going at it from the other way: from the parent window, find the element you want to append to and then use
.append()
and select the element in the iframe. For example: