Windows and Javascript - Clear contents.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob Videtta

    Windows and Javascript - Clear contents.

    Hi,

    Please Help!

    I have developed a custom JSP tag that produces Javascript to create a
    window and write HTML and Javascript to that window. This window
    displays an error message.

    The problem is this. When the page with the custom tag is refreshed
    without closing the (error) window the content written to the window
    in the first place is written again. Thus, the error message appears
    twice. The window source will then basically contain a replica of the
    code, appended to the end of the first section of code. What I want
    to do is clear the contents of the window before writing the HTML and
    Javascript to that window. I have found a method document.clear( )
    which does not seem to be supported by IE. Does anyone know how I
    achieve the same functinality?! Alternatively, I want to be able to
    close the window and create a new window (with an error message) but I
    don't know how I can check if the window is open. Remember that all
    the functionality must be contained within the Javascript output by
    the tag (the HTML page where the tag resides cannot be modified).

    Any help would be much appreciated. Thanks,

    Rob.
  • Lasse Reichstein Nielsen

    #2
    Re: Windows and Javascript - Clear contents.

    roberto.v.videt ta@accenture.co m (Rob Videtta) writes:
    [color=blue]
    > The problem is this. When the page with the custom tag is refreshed
    > without closing the (error) window the content written to the window
    > in the first place is written again. Thus, the error message appears
    > twice.[/color]

    Remember to close the document after writing to it (and open it before).
    I.e., the code to write to the error window is

    errorWindowRef. document.open() ;
    errorWindowRef. document.write( errorContent);
    errorWindowRef. document.close( );
    [color=blue]
    > The window source will then basically contain a replica of the
    > code, appended to the end of the first section of code. What I want
    > to do is clear the contents of the window before writing the HTML and
    > Javascript to that window. I have found a method document.clear( )
    > which does not seem to be supported by IE. Does anyone know how I
    > achieve the same functinality?![/color]

    Closing and reopening the document should be sufficient.
    [color=blue]
    > Alternatively, I want to be able to close the window and create a
    > new window (with an error message) but I don't know how I can check
    > if the window is open.[/color]

    !(errorWindowRe f.closed)

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Laurent Bugnion, GalaSoft

      #3
      Re: Windows and Javascript - Clear contents.

      Hi,

      Lasse Reichstein Nielsen wrote:[color=blue]
      > roberto.v.videt ta@accenture.co m (Rob Videtta) writes:
      >
      >[color=green]
      >>The problem is this. When the page with the custom tag is refreshed
      >>without closing the (error) window the content written to the window
      >>in the first place is written again. Thus, the error message appears
      >>twice.[/color]
      >
      >
      > Remember to close the document after writing to it (and open it before).
      > I.e., the code to write to the error window is
      >
      > errorWindowRef. document.open() ;
      > errorWindowRef. document.write( errorContent);
      > errorWindowRef. document.close( );[/color]

      Just to be clear, document.write also opens the document if it was not
      already open. As such, the call to document.open() before
      document.write( ) is not necessary.

      <snip>

      Laurent
      --
      Laurent Bugnion, GalaSoft
      Webdesign, Java, JavaScript: http://www.galasoft-LB.ch
      Private/Malaysia: http://mypage.bluewin.ch/lbugnion
      Support children in Calcutta: http://www.calcutta-espoir.ch

      Comment

      Working...