0

I'm trying to load a script from an external source after the user executes a click function. Like so:

$("#test-button").click(function() {
$.getScript("http://someurl.com/widget/javascript?key=4&t=uid&q=94777&show=all", function (data) {
        $('#myDiv').append(data);
    });
 });

The script I'm loading (which I have no control over) includes a document.write, so I'm getting this error when I execute the click:

It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.

I'm not sure how to get around this. I thought getScript would manage this.

3
  • If it contains document.write, you will not be able to add it like that or add it dynamically. Commented Mar 10, 2016 at 15:20
  • @epascarello That's what I thought. Any other work around besides an iframe? Commented Mar 10, 2016 at 15:23
  • stackoverflow.com/questions/53945/… Commented Mar 10, 2016 at 15:24

1 Answer 1

0

It seems like you have append the script like text

please see this example

            var script = document.createElement('script');
            script.src = '../web3.0/lib/charts/google-charts.js';
            document.body.appendChild(script);
Sign up to request clarification or add additional context in comments.

1 Comment

This will have the same error that the OP had. See: plnkr.co/edit/n60VzATrZHnZkYsxLHLv?p=preview

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.