从iframe打开模态窗口到父级 [英] open modal window from iframe into the parent

查看:119
本文介绍了从iframe打开模态窗口到父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带iframe的页面,在这个iframe中有一些链接应该在父窗口中打开一个模态窗口。问题是我没有权限将代码放入父窗口。我只能访问这个iframe。有没有办法可以通过jquery来实现这些限制?

I have a page with an iframe, and inside this iframe are some links that should open a modal window in the parent window. The thing is I dont have access to put code into the parent window. I just have access to this iframe. Is there a way this could be done with jquery with such limitations?

谢谢!

推荐答案

您可以使用JQuery插件 SimpleModal

You can use JQuery plugin SimpleModal

有一个名为appendTo的选项,你可以告诉你在哪里放置你的模态。这种方法的唯一问题是模态的叠加层会出现iframe的大小,因此您必须在打开它后给它所需的宽度和高度。

There's an option called "appendTo", where you can tell where do you put your Modal. The only problem with that approach is that the modal's overlay appear with iframe's size, so you must give it your desired width and height after you open it.

$('#div-modal').modal({
    appendTo: $(window.parent.document).find('body'),
    overlayCss: {backgroundColor:"#333"}, // Optional overlay style
    overlayClose:true, 
});
// Set overlay's width
$(window.parent.document).find('#simplemodal-overlay').css('width', '100%');

如果要作为模态打开的div位于父窗口中,则可以替换 $('#div-modal') with $(window.parent.document).find('#div-modal')

If the div you want to open as a modal is in your parent window, you could replace $('#div-modal') with $(window.parent.document).find('#div-modal')

这篇关于从iframe打开模态窗口到父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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