FreePX.net

Colorbox: How to quit iframe when clicking on a link

Posted in Webdesign and tagged , , . Posted on June 21, 2010 by admin

It’s time for some more technical web design stuff: When you use Colorbox for overlaying content in an iframe over the main website, you might want to link to another page in this iframe. If you do this, the new page will be shown in the same iframe with the colorbox design around it. Now if this new page doesn’t fit in the iframe, this will look quite messy and won’t be usable. So you want to open the new page in the parent window, but how to do this? The solution is quite simple, no JavaScript needed:

<a href="NEW SITE" target="_top">open in parent window</a>

By defining the target as _top, the iframe will be left and the site will be opend in the parent window. However, as colorbox usually opens and closes with an animation, you might want to animate the closing of colorbox. This is done by a simple JavaScript command:

<a onclick="parent.$.fn.colorbox.close();" href="NEW SITE" target="_top">
open in parent window with animation
</a>

23 Responses

  1. Rich Boy says:

    Thank you – Solved my problem perfectly ;)

  2. d says:

    Wow, this is the simplest solution to a problem I was having for a long time! Thanks!

  3. admin says:

    Thanks for the comments—glad I could help!

  4. Gunasegar says:

    Thanks Dude.. u solved my problem..

  5. Sathish Kumar says:

    Great work dude… U saved my time…

    Cheeeeeeers…

  6. VERY NICE DUDE =D

    You save my life hehehe … thanks!!!

  7. Fabio Reche says:

    Great dude! thank you…

  8. Mike says:

    Awesome! This was a re-accuring issue for a while. Worked GREAT! Thankx

  9. Kevin says:

    OMG !! THANK YOU BERRY BERRY MUCH !! :)

  10. Bill says:

    Thanks for the tip! One note,
    If you’re doing this in WordPress, you probably need to change:
    parent.$.fn.colorbox.close()
    to
    parent.jQuery.fn.colorbox.close()
    Otherwise, great job. Thanks.

  11. Dany Marcoux says:

    Thank you !

  12. Vlado says:

    Hi, big THANKS from Prague.

  13. Avi says:

    Works! Thank you!!!

  14. Hitesh says:

    Thanks , this solution provides great help…!!

  15. Ami says:

    pure genius – thank you!

  16. ML says:

    Bless you!

  17. Ben says:

    Thanks, saved my life!!!

  18. om says:

    Thanks you are great

  19. hamriti says:

    Hi,

    I have a very big problem, I’m developping a site web and I’m using colorbox plugin. It’s very nice, but I have a big problem with Google Chrome browser because :

    parent.$.fn.colorbox.close() doesn’t work in Google Chrome

    Please help me to find a solution to this issue !

    Thanks

  20. hamriti says:

    This is the error I have :

    Uncaught TypeError: Cannot read property ‘fn’ of undefined

    help !

  21. Ian Rosenfeldt says:

    I solved it by using target=”_parent” to close and open in the parent page or target=”_blank” to open on a new page

  22. hicham says:

    wonderfull thank you very match

  23. Sujin Joshi says:

    thanks!!
    tried a lot javascripting
    didn’t realize a simple target attribute could do the job.
    great share!!! :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

FreePX.net • free textures, photographs, tutorials and more Proudly powered by WordPress