FancyBox iframe returns parent.$ as undefined (using WordPress) FancyBox iframe returns parent.$ as undefined (using WordPress) wordpress wordpress

FancyBox iframe returns parent.$ as undefined (using WordPress)


It is undefined because WordPress runs jQuery in noConflict mode. Use this instead:

parent.jQuery.fancybox.close();

noConflict mode means $ does not equal jQuery. You have to explicitly use jQuery to access what you normally can access with $.


My answer is not related to wordpress, but one for fancybox in general.

in the iframe, if you have included the main jquery script(jquery-1.5.2.min.js), then it will conflict with the one on the main page, and parent.$.fancybox will not work in this case.

other jquery related stuff (like for eg: the tabs) will work inside the iframe.hence, it wont occur to a novice programmer that the second jquery script inside the iframe is the villain.


I had to do this:

window.top.window.$.fancybox.close();

Got type error before.