close fancy box from function from within open 'fancybox'

故事扮演 提交于 2019-12-28 04:06:41

问题


Hi all i want to be able to close fancyBox when it is open from within.

I have tried the following but to no avail:

function closeFancyBox(html){
    var re = /.*Element insert complete!.*/gi;
    if( html.search( re ) == 0 ){
        $.fancybox.close();
        //alert("foo");
    }
}

foo will open in dialog but will not close down. any hints?


回答1:


Try this: parent.$.fancybox.close();

See Fancybox API documentation.




回答2:


According to http://fancybox.net/faq

  1. How can I close FancyBox from other element? ?

Just call $.fn.fancybox.close() on your onClick event

So you should just be able to add in the fn.




回答3:


If you just want to close the fancy box it is sufficient to close it.

$('#inline').click(function(){
  $.fancybox.close();
});



回答4:


It is no use putting the .fn, it will reffers to the prototype.
What you need to do is $.fancybox.close();

The thing is that you are maybe experiencing another error from js.
There are any errors on screen?
Is your fancybox and jquery the latest releases? jquery is currently in 1.4.1 and fb in 1.3 something

Experiment putting a link inside the fancybox and put that function in it.

You probably had read that, but in any case, http://fancybox.net/api

One thing that you probably might need to do is isolate each part in order to realize what it is.




回答5:


You can even close fancybox by get close button id and call click event on that id.

<input type='button' value='Cancel' onclick='javascript:document.getElementById("fancybox-close").click();' />

It works for me!




回答6:


i had the same issues a longtime then i got the solution by the below code. please use

parent.jQuery.fancybox.close()



回答7:


Bit of an old thread but ...

Actually, I suspect that the answer to the original question about how to close the window from within the window has more to do with the fact that the click event is not attached to the element. If the click event is attached in document.ready the event will not be attached when fancybox creates the new window.

You need to re-apply the click event once the new window . Probably the easiest way to do this is to use onComplete feature.

This works for me:

$(".popup").fancybox({
    'transitionIn'  :   'fade',
    'transitionOut' :   'elastic',
    'speedIn'       :   600, 
    'speedOut'      :   400, 
    'overlayShow'   :   true,
    'overlayColor'  :   '#000022',
            'overlayOpacity'  : 0.8,
            'onComplete' : function(){$('.closer').click(function(){parent.$.fancybox.close();})}
});

Actually, after a bit of thought 'live' rather than 'click' or 'bind' might work just as well.




回答8:


Use this to close it instead:

$.fn.fancybox.close();

Judging from the fancybox source code, that is how they handle closing it internally.




回答9:


After struggling myself with this I found a solution that works just replace the $ with jQueryjQuery.fancybox.close() and I made it an inline script on an onClick. Going to check if i can call it from the parent




回答10:


For those who spent hours like me to find out the solution for inline type: window.setTimeout(function(){$.fancybox.close()},10);




回答11:


I ended up using:

<script>parent.$("#fancy_close").click();</script>

I guess the version of fancybox we have doesn't have a $.fancybox.close() function for me to call :(

FYI, I just wanted the page to close the fancybox, as it had finished its processing in PHP.




回答12:


Add $.fancybox.close() to where ever you want it to be trigged, in a function or a callback, end of an ajax call!

Woohoo.




回答13:


Within an iframe use - parent.$.fancybox.close();




回答14:


to close fancybox by funciton its necessary to make setTimtout to the function that will close the fancybox Fancybox needs some time to acept the close function If you call the function directly will not work

function close_fancybox(){
$.fancybox.close();
                     }
setTimeout(close_fancybox, 50);



回答15:


yes in Virtuemart its must be button CLOSe-continue shopping, not element, because after click you can redirect.. i found this redirect bug on my ajax website.




回答16:


To close ajax fancybox window, use this:

onclick event -> $.fancybox.close();
return false;  


来源:https://stackoverflow.com/questions/1829319/close-fancy-box-from-function-from-within-open-fancybox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!