SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2001
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy 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;


    Code:
    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.


    Code:
    <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>

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?
    Tab-indentation is a crime against humanity.

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2001
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Logic Ali View Post
    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


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •