Neir0
Neir0

Reputation: 13367

Load js from external site on fly

I want to load JS code from external site when user click on button. For example:

 <button onclick="LoadJSFromURL('facebook.com/blablabla')" />

and when user press button we attach new script to the document:

<script> Share.WorkUrl="http://MySite.com"; Share.UserId=5 </script> <script src="http://Facebookcom/blabalbal" ></script>

and then we must execute this script. Is it real?

Upvotes: 2

Views: 2558

Answers (1)

Pranay Rana
Pranay Rana

Reputation: 176886

check this : How do you dynamically load a javascript file from different domain?

var script = new Element("script", {src: "myBigCodeLibrary.js", type: "text/javascript"});

script.onload = script.onreadystatechange = function(){
    if (!this.readyState ||
        this.readyState == "loaded" || this.readyState == "complete") {
        //script is loaded
    }
};

Upvotes: 3

Related Questions