document.write

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jsuser
    New Member
    • Oct 2007
    • 7

    document.write

    Hi,
    I want to use document.write( ) in stead of innerhtml. But everything is getting cleared, while writing new content.
    I am losing registered callbacks on that object like onclick etc.
    But I want to preserve the previous things.
    Is this possible?
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by jsuser
    Hi,
    I want to use document.write( ) in stead of innerhtml. But everything is getting cleared, while writing new content.
    I am losing registered callbacks on that object like onclick etc.
    But I want to preserve the previous things.
    Is this possible?
    try...........

    [code=javascript]
    document.write( document.body.i nnerHTML+"your content goes here");
    [/code]

    Debasis Jana

    Comment

    • jsuser
      New Member
      • Oct 2007
      • 7

      #3
      Nope :(
      It does not work.
      I want to clear previous content, but not the registered onclick functions.
      This preserved my prev content, but still I lost onclick.

      Comment

      • dmjpro
        Top Contributor
        • Jan 2007
        • 2476

        #4
        Originally posted by jsuser
        Nope :(
        It does not work.
        I want to clear previous content, but not the registered onclick functions.
        This preserved my prev content, but still I lost onclick.
        On which Control you lost Registered "OnClick"?
        Post the related code here.
        And tell the problem elaborately.

        Debasis Jana.

        Comment

        • jsuser
          New Member
          • Oct 2007
          • 7

          #5
          I have code something like this -

          document.onclic k = func;
          document.ondblc lick = func;
          document.onkeyu p = func;
          etc.

          Now when I write

          document.body.i nnerHTML = html;

          When I click on the component, the 'func' gets called.

          But when my code is

          document.open() ;
          document.write( html);
          document.close( );

          The 'func' is never called.

          Comment

          • dmjpro
            Top Contributor
            • Jan 2007
            • 2476

            #6
            Originally posted by jsuser
            I have code something like this -

            document.onclic k = func;
            document.ondblc lick = func;
            document.onkeyu p = func;
            etc.

            Now when I write

            document.body.i nnerHTML = html;

            When I click on the component, the 'func' gets called.

            But when my code is

            document.open() ;
            document.write( html);
            document.close( );

            The 'func' is never called.
            Use code tags....

            You better to have it....
            [code=javascript]
            window.onclick = func;
            window.ondblcli ck = func;
            window.onkeyup = func;
            [/code]

            Debasis Jana

            Comment

            • jsuser
              New Member
              • Oct 2007
              • 7

              #7
              This is just extract of the code what I have.
              Actually I can not change that to window.onclick. I am not allowed to touch that code.
              Whatever I have to handle is while writing the content. :(
              Previously I was using innerhtml only, but for some issues I need to change it to document.write

              Comment

              • dmjpro
                Top Contributor
                • Jan 2007
                • 2476

                #8
                Originally posted by jsuser
                This is just extract of the code what I have.
                Actually I can not change that to window.onclick. I am not allowed to touch that code.
                Whatever I have to handle is while writing the content. :(
                Previously I was using innerhtml only, but for some issues I need to change it to document.write
                Well let me know ... what do you want to update?
                You want to clear the previous Screen but still want to have event registration.
                Right?

                Debasisi Jana

                Comment

                • jsuser
                  New Member
                  • Oct 2007
                  • 7

                  #9
                  Yes.
                  exactly :)
                  I just want to replace the content without disturbing anything else.

                  Comment

                  • dmjpro
                    Top Contributor
                    • Jan 2007
                    • 2476

                    #10
                    Originally posted by jsuser
                    Yes.
                    exactly :)
                    I just want to replace the content without disturbing anything else.
                    have a try this ..............

                    [code=javascript]
                    var child_s = document.body.c hildNodes;;
                    var i=0;
                    for(;i<child_s. length;){
                    document.body.r emoveChild(chil d_s[i]);
                    child_s = document.body.c hildNodes;
                    i=0;
                    }
                    document.body.i nnerHTML = "your_html_cont ent";
                    [/code]

                    Good Luck !

                    Debasis Jana

                    Comment

                    • jsuser
                      New Member
                      • Oct 2007
                      • 7

                      #11
                      I can not use innerhtml, bcoz innerhtml gives me problems when I have corrupted html. To overcome corrupted html content, I want to use document.write.
                      Otherwise in case of innerhtml, all my registrations are preserved.

                      I am losing the registraions when I do document.write

                      Comment

                      • dmjpro
                        Top Contributor
                        • Jan 2007
                        • 2476

                        #12
                        Originally posted by jsuser
                        I can not use innerhtml, bcoz innerhtml gives me problems when I have corrupted html. To overcome corrupted html content, I want to use document.write.
                        Otherwise in case of innerhtml, all my registrations are preserved.

                        I am losing the registraions when I do document.write
                        Again you can not do registration, after use "document.write ".

                        Debasis Jana

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #13
                          Originally posted by jsuser
                          I can not use innerhtml, bcoz innerhtml gives me problems when I have corrupted html. To overcome corrupted html content, I want to use document.write.
                          Otherwise in case of innerhtml, all my registrations are preserved.

                          I am losing the registraions when I do document.write
                          You cannot use document.write after the page has loaded. If innerHTML is giving you problems because of corrupted HTML, that's a good thing. Fix the corrupted HTML first.

                          Comment

                          Working...