简体   繁体   English

小时候打开fancybox(iframe)?

[英]Open fancybox(iframe) as a child?

I want, if possible, to open a fancybox as a child of a parent using iframe. 我希望,如果可能的话,使用iframe打开一个fancybox作为父母的孩子。

Is it possible to open an iframe ( constructed with fancybox ) and make the browser belive I have opened it using window.open so that functions like window.close() or window.opener.location.reload() still work ? 是否可以打开iframe(使用fancybox构建)并使浏览器相信我已经使用window.open打开它,以便window.close()window.opener.location.reload()等函数仍然可以工作?

The fancybox code is simple : fancybox代码很简单:

$("#custom_alert").fancybox({
        'width'             : w,
        'height'            : h,
        'autoScale'         : false,
        'transitionIn'      : 'none',
        'transitionOut'     : 'none',
        'type'              : 'iframe',
        //'scrolling'         : 'no'
    }).trigger('click');

EDIT : I cannot use functions like : 编辑:我不能使用如下功能:

function closePopup(){
     window.close();
     if(parent.jQuery().fancybox) {
      parent.jQuery.fancybox.close();
     }
}

I MUST use the window.close() function. 我必须使用window.close()函数。

A fix for my problem can be also to tell me why I cannot rewrite the close function like I did with alert or confirm. 我的问题的一个修复也可以告诉我为什么我不能重写关闭函数,就像我做的警告或确认。

EDIT 2: Thanks Raohmaru and JFK, after seeing the fiddle worked, I have made the function I need, but a strange thing ( for me ) is happening : 编辑2:感谢Raohmaru和JFK,看到小提琴工作后,我已经完成了我需要的功能,但是对我来说却是一件奇怪的事情:

The working code, if anybody else needs it is : 工作代码,如果有其他人需要它是:

(function() {
  var proxied = window.close;
  window.close = function() {
    if(parent.jQuery().fancybox) {
        parent.jQuery.fancybox.close();
    }
    else
        return proxied.apply(this, arguments);
  };
})();

This works for both fancybox and window.open cases. 这适用于fancybox和window.open情况。

My problem was this : I include some .js files in index : 我的问题是:我在索引中包含一些.js文件:

overwrites
fancybox pack
general scripts

If I put that function in general scripts, it works perfectly, but if I put it in the overwrites js ( where it should be ) it doesn't work ( no console errors, just nothing happens ). 如果我把这个函数放在一般脚本中,它可以很好地工作,但如果我把它放在覆盖js(它应该在哪里)它不起作用(没有控制台错误,没有任何反应)。 I have tried swapping positions on the includes, but no luck. 我试过在包含上交换位置,但没有运气。

This is why I couldn't make it work from the first place, because I always included it in the overwrites .js. 这就是我无法从头开始工作的原因,因为我总是把它包含在覆盖.js中。

What you can do is to validate IF the page has been opened in fancybox and perform the proper fancybox methods, otherwise just use your regular javascript methods (ie window.close() ) 你可以做的是验证如果页面已在fancybox中打开并执行正确的fancybox方法,否则只需使用常规的javascript方法(即window.close()

Having said that, within an opened page (either via window.open() or fancybox) you may have a function to close it like 话虽如此,在打开的页面内(通过window.open()或fancybox)你可能有一个关闭它的功能

function closePopup(){
 window.close();
}

associated to a close button/link like 与关闭按钮/链接相关联

<a href="javascript:;" onclick="closePopup()" >Close Window</a>

that for sure will close the popup window but not the fancybox so you can add the following : 肯定会关闭弹出窗口但不关闭fancybox,因此您可以添加以下内容:

function closePopup(){
 window.close();
 if(parent.jQuery().fancybox) {
  parent.jQuery.fancybox.close();
 }
}

and that will work for either the popup window or fancybox. 这将适用于弹出窗口或fancybox。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM