jpillora / xdomain

A pure JavaScript CORS alternative
https://jpillora.com/xdomain/
3.12k stars 270 forks source link

Dynamically loading xdomain.js after loading require.js results in "xhook is not defined" error #91

Closed jlubean closed 10 years ago

jlubean commented 10 years ago

When I dynamically load xdomain.js (v0.6.11) from JavaScript (instead of using a <script> tag in the web page) that has already loaded require.js, I get an error of "xhook is not defined" (see jsfiddle):

<script src="http://requirejs.org/docs/release/2.1.14/minified/require.js"></script>
<script>
var scriptTag = document.createElement('script');
scriptTag.setAttribute("type","text/javascript");
scriptTag.setAttribute("src", 'https://rawgit.com/jpillora/xdomain/gh-pages/dist/0.6/xdomain.js');
document.getElementsByTagName("head")[0].appendChild(scriptTag);
</script>

If I remove the require.js <script> tag above, I don't get the error (see jsfiddle).

My quick fix hack is to insert the following on line 161:

window.xhook = xhook;

jpillora commented 10 years ago

Hey @jlubean sorry for the late reply on this. I don't actually use requirejs, AMD support was added via a PR - hence the lack of support. Will attempt to debug though...

jpillora commented 10 years ago

This should be fixed now in 0.6.12 see http://jpillora.com/xdomain/example/requirejs/