0

I have a URL that has some JavaScript file, ImportantScript.js:

www.PrivateDomain.com/ImportantScript.js

I have another URL, www.ImportantBusiness.com, that has some other script file on its page with the following code:

$(document).ready(function ()
{
    // Code to read and execute ImportantScript.js
}

What code do I need for the browser viewing www.ImportantBusiness.com to read and execute ImportantScript.js from the URL www.PrivateDomain.com/ImportantScript.js

1
  • 1
    I assume just adding a normal <script src="..."> tag to the HTML isn't possible? Commented Aug 1, 2013 at 11:48

2 Answers 2

1

Try with $.getScript(), it shoud do what you want. See http://api.jquery.com/jQuery.getScript/

Sign up to request clarification or add additional context in comments.

Comments

1

You can use the following.

var script = document.createElement("script");
        script.src = "http://www.PrivateDomain.com/ImportantScript.js"
        script.onreadystatechange = function(){
            if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
                        done = true;
                        //call some function when done
            }
        };
        document.getElementsByTagName("head")[0].appendChild(script);

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.