I want, if possible, to open a fancybox as a child of a parent using iframe.
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 ?
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 cannot use functions like :
function closePopup(){
window.close();
if(parent.jQuery().fancybox) {
parent.jQuery.fancybox.close();
}
}
I MUST use the window.close() function.
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 :
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.
My problem was this : I include some .js files in index :
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 ). 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.