Con Fancybox, ¿cómo puedo abrir un enlace en la ventana principal (y cerrar Fancy Box)?

I'm using Fancybox to open a pop-up that allows the user to choose between two different methods of logging on to a site. I'd like clicking either of the links in the Fancybox to close the fancybox and open the link back in the parent web page.

¿Es esto posible?

Here's how I'm opening the FancyBox box:

         $("#logonChooser").click(function () {
                 href: 'LogonChooser.html',
                 type: 'iframe',
                 padding: 5

Here's the LogonChooser.html:

  <a href="LogInDatabase.html">Log In</a>
  <a href="LogInFacebook.html">Log In Facebook</a>

I can close the fancybox like so:

<a href="LogInDatabase.html" onclick="parent.$.fancybox.close();">Log In</a>

but I don't get the link back in the parent page.I'd like clicking on either of the links to close the fancybox and open the link in the page that spawned the fancybox, rather than inside the fancybox.

Any help is appreciated. I'm using Fancybox 2 if that helps, but am open to using the previous version if that is easier.

preguntado el 22 de mayo de 12 a las 16:05

I'm on a mobile so I can't give any full-blown example, but maybe this can get you started: give both of the links a class. In jQuery: click 'the class', close fancybox and window.location, is this.attr('href'). If needed I'll provide a fiddle later on. -

2 Respuestas

It should be sufficient when you add this to the links:


The linked page now will be opened in the parent page, no need to close the fancybox, because the fancybox will be replaced(it's also a part of the parent page)

contestado el 22 de mayo de 12 a las 16:05

Brilliant! So simple. "True genius is the ability to scrutinize the obvious..." - Hairgami_Master

Prueba el $.fancybox.close método.

contestado el 22 de mayo de 12 a las 16:05

Thanks for the suggestion- it doesn't propogate the link up into the parent page. - Hairgami_Master

Did you try the onClosed option? I have seen it done like onClosed': function() { window.parent.location.href = ''; } - Mali

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.