There is no "easy" way to do this. By default talking between domains is disabled in javascript. This is good because say a site opened an iframe to your website, browsed through the dom to find the password field and saved your password (and no that wont be a bunch of symbols like you see in the browser). I would highly recommend to having the viewer and your site on the same server.
You might be able to get around it by doing a cross site scripting (xss) attack on yourself. Make a script that takes in raw javascript and adds it to the document. Then when you need to execute the API you will need to redirect to that page. You need to preserve window.opener though and at this point I am unsure if this will work (I am pretty sure domain limitations would hit for attempting to use a script frame for the same purpose). All in all it isn't something that you would want to be doing.