I spent ages digging around for this, and it should be simple!
Actually, it is simple. But only when you know how. This is how you add a close button to the contents of a Fancybox window (ie, the contents inside the iFrame) :
<a href=”#” onClick=”parent.jQuery.fancybox.close();”>Close This Window</a>
So there you go.
Tags: 18 Comments

Hello.
I am also doing Web Development and learn lot about HTML, CSS, JavaScript etc. Im now moving onto PHP and first point I need to learn is include.
Its very confusing because not sure how it works. It be great if you can show me a very simple PHP include with header, footer and main.
Thanks
Umar
That is a hell of a comment Umar.
Thanks to OP for this simple, easy solution.
Cheers for the code. I always find those javascript events fiddly to say the least.
YOU SIR! Are a brilliant! I almost spent a lot of time trying to figure out how to create a close button for a fancybox but I just searched it and here u are!
Thanks for this bit of info! I was googling for a while before i stumbled onto this blog. Simply worked! Thanks!
thank you its works
AHHH!!!! thank you so much for posting that one line of code. I was going bald by yanking out my own hair.
Thanks again
Pleasure David, that’s why I posted it, to avoid general baldness amongst frontend coders the world over lol
yay…thanks mate
Wow.. works like a charm. I’ve try it and this is the code what I’m looking for. Thank you very much Alex. Your simple solution solving my big problem.
Thank you! Seriously, this is so hard to find. You are awesome for sharing this.
I did have trouble with your exact code but when I used it in a button I got it to work. In firefox it kept trying to find a document with the hashtag (#). Here is how I used it in the button:
Close
You are awesome, thanks a million!!!
OK, so that didn’t show the code. Try that again.
<button onclick=”parent.jQuery.fancybox.close();”>Copy Text</button>
ah the fun of sticking code into WP. I should sort it out one day really.. Glad it helped you, cheers
How about opening a new web page in a new window upon closing the iframe? Can’t seem to figure out how to combine the two.
ThanQQQQ u so much bossssssssss,,workin
Thanks !!!!!!! <3
Close This Window……code does not work on chrome browser.
Thank you so Much Alex. i search on google and find first result of your site. now i am feeling lucky