Append embed code (script tag with dynamic variables)?

845 Views Asked by At

I need to append embed code with dynamic variables: http://www73.zippyshare.com/v/57510152/file.html

var c = '<script type="text/javascript">var zippywww="73";var zippyfile="57510152";var zippytext="#000000";var zippyback="#e8e8e8";var zippyplay="#ff6600";var zippywidth=850;var zippyauto=false;var zippyvol=80;var zippywave = "#000000";var zippyborder = "#cccccc";</script><script type="text/javascript" src="http://api.zippyshare.com/api/embed_new.js"></script>';

$("body").html(c);

I've seen solutions using getScript and document.createElement("script") but I receive the embed code dynamically via an API.

  • I could use getScript for the embed_new.js
  • I could possibly write the vars to the current DOM.
  • how to place the output into a desired position then?

Test: http://jsfiddle.net/y658cb9x/

1

There are 1 best solutions below

3
On

Create the script with e.g. jQuery like

$("<script />", {
 html: "Your HTML"
}).appendTo("body");

since you can not create a script-block in a JavaScript block. The string will be parsed like native HTML.