close fancy box from function from within open 'fancybox' - javascript

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?

Try this:
parent.$.fancybox.close();
See Fancybox API documentation.

According to http://fancybox.net/faq
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.

If you just want to close the fancy box it is sufficient to close it.
$('#inline').click(function(){
$.fancybox.close();
});

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.

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!

i had the same issues a longtime then i got the solution by the below code.
please use
parent.jQuery.fancybox.close()

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.

Use this to close it instead:
$.fn.fancybox.close();
Judging from the fancybox source code, that is how they handle closing it internally.

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

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

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.

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

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

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);

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.

If anyone is looking for how to close all instances in Fancybox 4 you can just use Fancybox.close();

To close ajax fancybox window, use this:
onclick event -> $.fancybox.close();
return false;

Related

FullPage JS: How to disable it for an unique page?

I have a problem with FullPage JS, and I come to ask for help :)
My problem is: I want to disable FullPage for a single page of my Website.
FullPage is made for little page, but my website has 1 long page, where I want to disable FullPage.
The file has the .ejs extension, instead of .html extension. The pages are in different EJS file.
I searched on the FullPage's Github, and it indicates me the destroy('all') method, but I've found a lot of way to write it, I tried 3 methods, and I don't know why, it doesn't work.
Does any of you know how to disable FullPage JS on a single page of the Website ?
I tried 3 methods.
1st Method tried:
document.querySelector('#destroy').addEventListener('click', function(e){
e.preventDefault();
fullpage_api.destroy('all');
});
2nd Method:
$('#destroy').click(function () {
$.fn.fullpage.destroy('all');
});
3rd Method:
function DestroyFullPage() { //default is 700.
$.fn.fullpage.destroy('all');
}
As Alvaro suggested, I tried something like this:
<script>
window.onload = function() {
alert('Ready ?');
fullpage_api.destroy('all');
alert('Done');
}
</script>
The first alert works fine, but the second never appear on my screen, and FullPage isn't destroyed.
Am I wrong in my syntax ?
Thanks
PS: Excuse my English, I'm french, but at least, I try :D
If you wonder how to use the destroy function, you can check the demo provided on the fullPage.js docs:
https://codepen.io/alvarotrigo/pen/bdxBzv
Which basically uses fullpage.js version 3 (no jQuery required) to do so:
fullpage_api.destroy('all');
There's no difference at all between your 2nd method and the 3rd one. In fact, 3rd method won't work until you call the DestroyFullPage somewhere else.
And the 1st one should only be used when initialising fullPage.js with jQuery. So, using $('#fullpage').fullpage(options) instead of new fullpage('#fullpage', options);

popup window from right on the page load through jquery

i searched on internet for j Query or java script code that do some work for me like when the the page completely loads a popup window come out from the right side for some time and then disappears after some specific time but i couldn't succeed. i need yours help and favor in this regard.(send me any link of document related my question or any you tube or any other media link from where i could get help now and for future).
thanks in advance
you can use jquery' anitmate function Animate()
some thing like this: pseudocode
$('#yourDivorModalBox').animate({
right: '+=50',
height: 'toggle'
}, 5000, function() {
// Animation complete.
});
Have you checked jQuery's ready() function? There's also window.open
$(document).ready(function() {
newwindow = window.open('http://www.google.com/','testme','height=200,width=300');
});
Then use setTimeout() to close the popup.

Fancybox Recursion causes a stack overflow

It seems that when I add an afterClose callback to my fancybox I'm getting this error:
Uncaught RangeError: Maximum call stack size exceeded
This is the code I am using:
$("a.termsLink").fancybox({
type : 'iframe',
fitToView : false,
width : 450,
height : 600,
afterClose : function(){
$('#regForm').click();
}
});
What is supposed to happen is when the termsLink box closes, the regForm is supposed to open. I've expiremented with differnt callbacks, but the issue that I am running into seems to be unaffected by this.
The solution appears to be as follows:
afterClose : function(){
setTimeout(function(){$('#regForm').click();}, 1);
}
However that feels like a very hacky method to me, the issue seems to be that the fancybox code trys to call the new box while the animation for the other box is still running, which causes this issue. Is this a documented issue with FancyBox? Or is this a function of the way jQuery animation event work? Is there a more elegant solution to this issue?
If you're using Twitter Bootstrap < 2.3.1, it's known to cause this exact issue (I just experienced it, and upgrading bootstrap solved the problem)
More details here: https://github.com/fancyapps/fancyBox/issues/519
Try
$("a.termsLink").fancybox({
type : 'iframe',
fitToView : false,
width : 450,
height : 600,
afterClose : function(){
$('#regForm').focus();
}
});
although what you have should work you're right. Unsure but check the script doesn't close all fancybox's open. if the #regForm is being opened into a fancybox hence why you'd need the timeout.
Looking into the fancybox script they use this function
function _cleanup() {
overlay.fadeOut('fast');
title.empty().hide();
wrap.hide();
$.event.trigger('fancybox-cleanup');
content.empty();
currentOpts.onClosed(currentArray, currentIndex, currentOpts);
currentArray = selectedOpts = [];
currentIndex = selectedIndex = 0;
currentOpts = selectedOpts = {};
busy = false;
}
This basically confirms what I was saying before. All the instances of fancybox are cleared after this function is run. So even though you've got one opening straight after it's being cleared before really being shown. The solution you've come up with seems to be the better solution unless you want to fiddle with the fancybox script yourself :)
Are you sure the problem is related to the click function?
I found the same problem including, by mistake, two jQuery versions
(jquery-1.2.6.pack.js and jquery-1.4.4.min.js)
Removing the last one solved the problem.
I checked this because of this topic loading jquery twice causes an error?.
You could try to check it.

jQuery .slideDown executes twice instead of once

I'm new to jquery and bumped into a problem i can't fix
I want that on pageload my content is sliding down so i use the next code:
$(document).ready(function () {
$("#content").hide();
$("#content").slideDown(1000);
});
when i load the page the content slides down narmally, than the content gets hidden and slides down again.
When i go to the css and do #content{display: none;} instead of $("#content").hide(); everything works fine. (can't use this for browsers without js)
Does anyone know the cause of this?
Thanks!
You are saying that everything works fine while using css #content{display: none;}
than i offer u to use Jquery .css() method( http://api.jquery.com/css/ )..
u can use it like :
$(document).ready(function () {
$("#content").css( { 'display' : 'none' } );
$("#content").slideDown(1000);
});
sipmle as that.
and i also agree with #Billy Moon , it can be a browser specific bug or u may be calling a page refresh command, somewhere within ur code.
Your code has no problem inside. It's somewhere else in your code.
isn't that function call in some function that is called twice?

Jquery Fancybox not working after postback

I have a Fancybox (or more accurately) a number of fancy boxes on an asp.net page.
My Fancybox (jquery plugin) works fine until a postback occurs on the page then it refuses to work.
Any thoughts? Anyone experienced similar behaviour?
UPDATE : Some Code..
I have a databound repeater with a fancybox on each repeating item.
They are instanciated by (outside the repeater)
$(document).ready(function() {
$("a.watchvideo").fancybox({
'overlayShow': false,
'frameWidth' : 480,
'frameHeight' : 400
});
});
The anchor tag is repeated..
href="#watchvideo_<%#Eval("VideoId")%>"
As is a div with
id="watchvideo_<%#Eval("VideoId") %>
As is a script element that instanciates the flash movies
Yes the VideoIds are being output the the page.
UPDATE : It's not a problem with the flash..
It is not a problem with the flash as i've tried it without the flash, it wont even pop a window with a simple message in.
UPDATE : I wonder if it is the updatepanel.
Rebinding events in jQuery after Ajax update (updatepanel)
-- lee
The problem is in using $(document).ready() to bind the fancybox. This code is only executed once, when the page is originally loaded. If you want the fancybox functionality on every postback, synchronous or asynchronous, replace the $(document).ready() with pageLoad(sender, args). i.e.
function pageLoad(sender, args) {
$("a.watchvideo").fancybox({
'overlayShow': false,
'frameWidth' : 480,
'frameHeight' : 400
});
}
see this answer for more info
Could it be that the instantiating code is being inserted at a piece of code which is not run after a postback?
It was the Update panel as described
here.. Rebinding events in jQuery after Ajax update (updatepanel)
As suggested I simply replaced
$(document).ready(function() {
$("a.watchvideo").fancybox({
'overlayShow': false,
'frameWidth' : 480,
'frameHeight' : 400
});
});
with
function pageLoad(sender, args)
{
if(args.get_isPartialLoad())
{
$("a.watchvideo").fancybox({
'overlayShow': false,
'frameWidth' : 480,
'frameHeight' : 400
});
}
}
and it worked!
-- Lee
This might help someone else, but FancyBox appends it's code to the <body> element... which is all fine and well, but resides OUTSIDE the asp.net <form> element. My postback problems went away when I modified FancyBox to append its dom objects to the <form> element:
$('body form:first').append( ... );
I had a similar problem with a paged grid-view. The first page of the grid was launching the fancybox while the remaing did not.
I thought it could be an issue related to the UpdatePanel which refreshes only a portion of the screen.
I solved the issue replacing this:
<script>
$(document).ready(function () {
$("a.small").fancybox();
});
</script>
with this:
<script>
function pageLoad(sender, args) {
$("a.small").fancybox();
};
</script>

Categories