How do you pass a variable as a part of an URL?
Easy! Since you don't mind using javascript a simple solution is as follows
var scriptElement = document.createElement("script"); scriptElement.src = "http://markets.financialcontent.com/stocks?Module=snapshot&Ticker=" + encodeURIComponent("$SPX+" + sym) + "&Output=JS"; document.head.appendChild(scriptElement);
This code creates an script element with the source being "http://markets.financialcontent.com/stocks?Module=snapshot&Ticker=" + encodeURIComponent("$SPX+" + sym) + "&Output=JS". Then it appends it to the head of the webpage.
The final HTML being:
<script> var sym = "MSFT"; document.write("\<script src='" + "http://markets.financialcontent.com/stocks?Module=snapshot&Ticker=" + encodeURIComponent("$SPX+" + sym) + "&Output=JS" + "'\>\</script\>"); </script>
The reason that this solution won't work is as follows:
Codepen is an HTTPS site which means it WILL NOT serve HTTP content. To be honest I have no idea why Codepen serves the HTTP script. How to fix this? Well, there really is only one easy solution:
Instead of using Codepen use a local HTML file and just open that, if you have your own HTTP server you can use that.
Quick how-to guide:
1) Open a text editor
2) Type the following
<html> <head> <script> var sym = "MSFT"; document.write("\<script src='" + "http://markets.financialcontent.com/stocks?Module=snapshot&Ticker=" + encodeURIComponent("$SPX+" + sym) + "&Output=JS" + "'\>\</script\>"); </script> </head> <body> </body> </html>
3) Now hit the "Save As" button and save it as a .html file
4) Open it!
5) Have fun :)