Note that there are some explanatory texts on larger screens.

plurals
  1. POCross-domain templating with Javascript
    text
    copied!<p>I'm currently building a Javascript library that can be used to easily create embeddable media based on the URL of a media file, and then be controlled using Javascript methods and events (think something like the Flash / Silverlight <a href="http://longtailvideo.com/" rel="nofollow noreferrer">JW player</a>). </p> <p>Of course, i could simply cat all the html tags from the Javascript library and send that to the browser:</p> <pre><code>function player(url) { document.write('&lt;object type="foo"&gt;&lt;param name="something" value="bar"&gt;' + &lt;param name="source" value=" + url + '/&gt;&lt;/object&gt;'); } </code></pre> <p>But i think this is a very ugly practice that tends to create unmanageable code that is unreadable when you review it a few weeks later. </p> <p>So, a templating solution seems to be the way to go. I've been looking to <a href="http://embeddedjs.com/" rel="nofollow noreferrer">EJS</a> because it loads the templates using AJAX, so you can manage your templates in separate file instead of directly on the HTML page. </p> <p>There's one 'gotcha' with that: my library needs to be completely cross-domain: the library itself could be located on foo.com while the serving site could be located on bar.com. So if bar.com would want to add a media player using the library it needs to do an AJAX call to a template located on foo.com, which won't work because of the same-origin policy in browsers. </p> <p>AFAIK, there's no library that uses something like JSONP to read and write templates to get around this problem.</p> <p>Could anyone point me to a solution for this problem?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload