Send object to remote javascript file

So if I create a yahoo pipe icon in my site yahoo gives me this code

<script src="http://pipes.yahoo.com/js/listbadge.js">{"pipe_id":"USER_ID","_btype":"list"}</script>

      

Note that it is passing the object literal to the remote script. I would like to do something similar with my own scripts, how do you interact with this input?

+1


source to share


1 answer


You cannot pass variables in the same way as originally. What Yahoo does is, in the listbadge.js file, it loops through all the tags <script>

on the page until it finds the one that included it, and then parses the innerHTML as JSON.

Their source was a little confusing, but here's my best understanding of it.



var scripts = document.getElementsByTagName("SCRIPT");

for (var i = 0; i < scripts.length; i++) {
    var includeString = scripts[i].src;
    if (includeString.match("listbadge.js")) {
        if (scripts[i].innerHTML){
            var passedVariables = parseJson(scripts[i].innerHTML);
        }
        break;
    }
}

      

+3


source







All Articles