Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: document.write?

  1. #1
    New Coder
    Join Date
    Jun 2009
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    document.write?

    why document.write takes me to another page?
    i want to write in the original not another page? what should i do?

    <html>

    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>New Page</title>
    <script>
    function click(){
    document.write('<div style="position: absolute; width: 47px; height: 47px; z-index: 1; left: 132px; top: 66px" id="layer1"> <img border="0" src="file:///H:/Documents%20and%20Settings/Administrator/Desktop/ajax-loader.gif" width="48" height="47"></div>');
    return false;
    }
    </script>
    </head>

    <body>

    <p align="center">&nbsp;</p>
    <p align="center">&nbsp;</p>
    <p align="center"><a onclick="return click()" href="javascript:void(0)">link</a></p>

    </body>

    </html>
    Last edited by Zpixel; 06-17-2009 at 03:10 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,037
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    document.write statements must be run before the page finishes loading. Any document.write statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page. So document.write is at best really only useful to write the original content of your page. It cannot be used to update the content of your page after that page has loaded.

    Your best plan is to load the <div> at the outset and use style="display:none", revealing the <div> onclick.




    Jesus saves, Moses invests, Allah protects, and Cthulhu thinks you'd make a nice sandwich.

  • #3
    New Coder
    Join Date
    Jun 2009
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    should i use DOM objects to create elements after loading? is it possible?
    thank you.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,859
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    You may either change the Object.style.display as Philip mentioned or use createElement() and appendChild methods to add new elements.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    New Coder
    Join Date
    Mar 2009
    Posts
    74
    Thanks
    3
    Thanked 3 Times in 3 Posts
    createElement is probably best, but you can also give a <div> an id (<div id="mydiv")>) and then change the innerHTML property up in the onclick handler function:

    Code:
    document.getElementById('mydiv').innerHTML='some text here, some <div style="font-size:50px;">CSS & HTML</div>, <img src="myimg.jpg">, etc.'

  • #6
    New Coder
    Join Date
    Jun 2009
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you all.


  •  

    Posting Permissions

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