A strange problem with asynchronous loading

Hello guys,
I have a strange problem with asynchronous loading.
There is this function, it loads asynchronously, no problem.
test.js has some javascript code, like;

document.write ('Let me write on screen');

My problem is, it doesn’t print this code on screen.

Do you have any idea about why? What am I doing wrong?

All the help is appreciated.

<script type="text/javascript">
    (function () {
        function async_load() {
            var s = document.createElement('script');
            s.type = 'text/javascript';
            s.async = true;
            s.src = 'test.js';
            var x = document.getElementsByTagName('script')[0];
            x.parentNode.insertBefore(s, x);
        }
        if (window.attachEvent)
            window.attachEvent('onload', async_load);
        else
            window.addEventListener('load', async_load, false);
    })();
</script>

One problem is you’re calling document.write in a document that is no longer open for writing. Try changing to an alert().

Any console errors?

Hello Logic Ali,
alert() function works ok, but I couldn’t understand; calling document.write in a document that is no longer open for writing statement. What do you mean by that?

Best