Question

So if i am setting up a yahoo pipes badge on my site, yahoo gives me this code

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

Notice its passing an object literal to the remote script. i would like to do something similar with my own scripts, how do you interact with that input?

Was it helpful?

Solution

You can't actually pass variables around like that natively. What Yahoo is doing there is that in their listbadge.js file, it searches through all the <script> tags on the page until it finds the one which included it, and then parses the innerHTML as JSON.

Their source has been slightly obfuscated, 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;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top