开发者

Call jQuery from a Fancybox iframe?

I have loaded a page in Fancybox using a iframe. But when I try t开发者_JS百科o 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.

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


    }
  );                

});


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);
}


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

Example:

<body> 
<script>
alert(parent.$('body',document).html())
</script>
</body>

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜