0

Hi I am calling a few javascript functions from a same domain iframe by using the parent.myFunction() method. The only problem with this is that the functions seem to need to be in the global scope to be accessed this way. I would like to put all my functions in jQuery's document.ready wrapper function

Can I access functions within jQuery's document.ready wrapper from an iframe somehow? I know it is a scope issue, but how would I access myFunction if it were within jQuery's document.ready wrapper from a same domain iframe?

Thanks!

1
  • Why would you want to put all your functions in the document.ready wrapper? Commented Jul 25, 2012 at 19:45

1 Answer 1

2

No, you can't. Just put them outside the local scope of $.ready, preferably namespaced to avoid global scope pollution.

If you would want to define them on document ready, you still can put them in the global scope:

jQuery(function($) {
    window.someFunc = function(){ ... };
    // or better
    window.namespace = {
        func: function(){ ... }
    };
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.