redoc01
redoc01

Reputation: 2307

call function in jquery plugin from iframe

How do i call a JQuery plugin function from within an iframe?

 (function($){

         $.fn.jqueryEx = function() {

               function CallThisFunctionFromIframe(){
               }

         }



 })(jQuery);

Edit

The iframe is on the same domain as parent document.

Upvotes: 3

Views: 892

Answers (2)

redoc01
redoc01

Reputation: 2307

(function($){

     $.fn.jqueryEx = function() {


         $.fn.jqueryEx .CallThisFunctionFromIframe= function() {

             alert('hello');

         }  

     }


 })(jQuery);

Call this from within the iframe

 $(document).ready(function() {

     window.parent.$.fn.jqueryEx.CallThisFunctionFromIframe();

 });

Upvotes: 2

Oybek
Oybek

Reputation: 7243

I can suggest you this approach. Just wrap the logic you want to call into the function.

<script type="text/javascript"> 
//<![CDATA[
    function CalledFromChild() {
        // Stuff triggered from child
        alert("What ever");
    }
//]]>
</script>

and in the iframe you can do so.

<script type="text/javascript">
    //<![CDATA[
    window.parent.CalledFromChild();
    //]]>
</script>

Upvotes: 0

Related Questions