Take the 2-minute tour ×

I have loaded a page in Fancybox using a iframe. But when I try to perform jQuery functions within that iframe it won't work. How do I access the iframe page or content so that I can perform jQuery on that page? I tried this below but doesnt work.

parent.jQuery("#showcasef", jQuery.browser.msie ? parent.jQuery('body')[0] : parent.jQuery(document)).live('submit', function(e) {  
        return false;
        var pho_id  = jQuery('#pho_id').attr('value');
        var showcase =jQuery("#showcase_pho option:selected").val();
        var action = "showcasep";



share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

You will need to include jQuery again inside that iframe, or try...

parent.$('body').text('Does it work?');

Or maybe if that is too long, make a wrapper

function $() {
     return parent.jQuery.call(this, arguments);
share|improve this answer
Thanks but can't get it to work. MUST still be doing something wrong. I provide a code sample above if that helps. Thx! –  Panama Jack Oct 11 '10 at 1:56
@Pjack Is the iframe on the same domain? Also, you are returning false from the function in the 2nd line. This will stop the rest of the anonymous function from being ran. –  alex Oct 11 '10 at 2:12
Yes it is on the same domain. Oops, I moved it there to test something, I moved it back to the end. However it still doesn't work. Thx –  Panama Jack Oct 11 '10 at 2:53
Im an idiot. I figured out the problem. I have a js file with all my functions. Well I use a script that can use different header templates. The header being called on the page did not have my js file included. Once added, it worked. Duh. Thanks for the answers. Yes I just needed to include jQuery and my js file again. –  Panama Jack Oct 11 '10 at 3:53
@Pjack Glad you figured it out :) –  alex Oct 11 '10 at 4:52
add comment

If both documents depend on the same domain, you can access jQuery by prepending "parent" to your statement.



Notice the 2nd argument is set to document. This is recommended, otherwise the context will be the document of the parent window, not the document inside the iframe. But as I did not know if this kind of use is really secure, especially if you use external plugins, I would prefer the additional including.

share|improve this answer
add comment

Your Answer


