-1

Page a.com loads a javascript file from b.com like this:

<script src="http://b.com/file.js"></script>

b.com/file.js adds some content to a.com.

The file.js is like this:

document.write("<script ... <link rel=\"stylesheet\" ... <div> ... <form> ...");

But I know document.write is not good. But what are the alternatives? I don't think it's "ok" to add complete html code inside document.write ... or not?

2
  • 1
    This link might help you:- stackoverflow.com/questions/3418041/… Commented Jun 29, 2014 at 19:44
  • So should I add this <script src="http://b.com/file.js"></script> inside a div? I am not sure if I understand it. Commented Jun 29, 2014 at 19:56

1 Answer 1

1

There is nothing "not good" about using document.write here, especially when you want to add in some <script> to the page. If you are just using it to add DOM elements, you can consider using some DOM manipulation methods.

Sign up to request clarification or add additional context in comments.

Comments

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.