Open fancybox (iframe) as a child?

I want, if possible, to open fancybox as a child of the parent using an iframe.

Is it possible to open an iframe (built with fancybox) and do a browser verification, I opened it with window.open so that functions like window.close() or window.opener.location.reload() still work?

The fancybox code is simple:

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

EDIT: I can't use features like:

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

I MUST use the window.close () function.

You can also fix the problem to tell me why I cannot rewrite the close function, as was the case with a warning or confirmation.

EDIT 2: Thanks to Raohmaru and JFK, after seeing the fiddle, I did the function I needed, but a strange thing (for me) happens:

Working code, if someone else needs it:

 (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.

My problem was this: I include some .js files in the index:

 overwrites fancybox pack general scripts 

If I put this function in shared scripts, it works fine, but if I put it in rewritable js (where it should be), it will not work (no console errors, just nothing happens). I tried replacing the positions on the tabs, but no luck.

That's why I couldn't get it to work from the first place, because I always included it in overwrites .js.

+4
source share
1 answer

What you can do is check if the page was opened in fancybox and the correct fancybox methods were executed, otherwise just use regular javascript methods (i.e. window.close() )

Having said that on an open page (via window.open() or fancybox) you might have a function to close it, like

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

associated with a close / link button e.g.

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

which will probably close the popup but not fancybox, so you can add the following:

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

and this will work either in a popup or in fancybox.

+1
source

All Articles