如何从iframe在浏览器中打开弹出窗口 [英] How to open a pop up in a browser from an iframe

查看:436
本文介绍了如何从iframe在浏览器中打开弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





在我的一个项目中,我有一个显示产品图像的iframe。当用户单击图像时,将打开一个弹出窗口以查看大尺寸图像。我在这里使用jquery colorbox( http://www.jacklmoore.com/colorbox/ [ ^ ])弹出图片。



问题是我希望弹出窗口在浏览器窗口中打开,但目前它在iframe内打开。





请帮助...........



谢谢

Swarup

Hi,

In one of my project i have an iframe where product images are displayed. When user will click the images a pop up will open to view the large size of image. Here I am using jquery colorbox(http://www.jacklmoore.com/colorbox/[^]) for the image pop up.

The problem is i want the pop up to be open in the browser window, but currently it opens inside the iframe.


Please help...........

Thanks
Swarup

推荐答案

你做不到。由于它是一个模态弹出窗口,它将始终在IFrame内打开。



您可以使用 window.open(),以便它将在当前浏览器窗口中打开。但是我想这对你没有帮助。



所以,你做了类似下面的事情。



- >从父窗口而不是IFrame打开此图片。

- >为此你可以调用父类的功能,例如

You can''t do that. As it is a modal popup, it will always open inside the IFrame.

You can open an window using window.open(), so that it will open over the current browser window. But that will not help you I guess.

So, you have do something like below.

-> Open this image from parent window not IFrame.
-> For that you can call the function of parent like
window.parent.MyFunction(dataToSend);



这里 MyFunction 在父窗口内定义。

dataToSend 是您要发送给父母的数据。



- >现在根据数据,只需在 MyFunction 中调用此模态弹出图像。



你能实现吗?试一试。

随意问任何疑问。我们将讨论。



[更新]

对于权限被拒绝的问题

当IFrame和Parent表单位于不同的域时,会出现此问题。

我们也可以修复此问题。

我已经为此写了一个提示。



你可以参考 - 与跨域IFrame的通信 - 跨浏览器解决方案 [ ^ ]。



请尝试这个并告诉我。


Here MyFunction is defined inside parent window.
And dataToSend is the data you want to send to parent.

-> Now according to the data, just invoke this modal popup image inside that MyFunction.

Can you implement this ? Give it a try.
Feel free to ask any doubts. We will discuss.

[Update]
For Permission denied issue
This issue comes, when the IFrame and the Parent form are in different domain.
We can also fix this.
I have written one tip for this.

You can refer - Communication with Cross Domain IFrame - A Cross Browser Solution[^].

Please try this and let me know.


检查一下在弹出窗口中使用iframe [ ^ ]


嗨Swarup,

您是否尝试使用''iframe''内的子窗口的''target''属性。

理想情况下,我们有空白,父母,自我和顶级。如果在子窗口中使用空白或顶部,则在iframe中将其作为新窗口打开。请检查一次。



谢谢,

Ravi
Hi Swarup,
Did you try with ''target'' attribute for your child window inside the ''iframe''.
Ideally we have blank, parent, self and top. If you use either blank or top to the subwindow with in iframe it opens as new window. Pls check this once.

Thanks,
Ravi


这篇关于如何从iframe在浏览器中打开弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆