That's the problem was talking about in my comment. You are calling document.write(MyHtml)
after the document was fully loaded.
It will completely replace the document (see the documentation). Inspect it, you will see that there is an empty head
(also see this and this example).
Use other methods to manipulate the DOM.