knowing when a htmlpage is opened

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BeMe
    New Member
    • Jul 2008
    • 12

    knowing when a htmlpage is opened

    Hi,

    I have a button on an asp page, when pressing it a html page opens with a table rendered on it, that page remains open, and when pressing the button again, i want to bring the focus to the open page, or - open a new page.
    what happens now, is that if i press the button 5 times, i have on the old page - 5 tables :( how could i prevent that?
    my code is:
    Code:
    var taskWindow = window.open("", "viewTaskWindow");
    Thanks
    Last edited by gits; Sep 3 '09, 11:34 AM. Reason: added code tags
  • BeMe
    New Member
    • Jul 2008
    • 12

    #2
    my code is: (I added another row)
    Code:
    var taskWindow = window.open("", "viewTaskWindow");
    taskWindow.document.write(taskListTable);
    Last edited by gits; Sep 3 '09, 11:35 AM. Reason: added code tags

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5388

      #3
      you could use the window's closed property to identify wheter the window is opened already ...

      kind regards

      Comment

      • BeMe
        New Member
        • Jul 2008
        • 12

        #4
        i'm really new with java script and i don't know how to do it, i tried a few ways but with no succeed, what i want to do is- i have an xsl and i want it to be renderd on the html page - once:

        Code:
        taskListTable = xml.transformNode(xsl);
        var taskWindow = window.open("", "saveTaskWindow");
        taskWindow.document.write(taskListTable);
        i can't ask about the window because i open it right away.

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          You already have a reference to the child window opened.
          So all you have to do is check to see if it's opened or closed. To do this you use the window's closed property.

          Comment

          • BeMe
            New Member
            • Jul 2008
            • 12

            #6
            what's written in the code you gave me a link to, the variable 'myWindow' is not defined any where, when i tried that, i got an exception that - myWindow.closed is null. i'll tell you exactlly what i do:
            i have a c# code (a btn), when that btn is pressed, i invoke a func that's written on default.aspx, that func opens a html page with a table, and that's it.
            then, if i don't close the new html page and press again the btn, it doesn't open a new page, it just renders the table again in the exsisting html page.
            so - the html page, after it opens on the first time is not a child any more...
            what can i do??

            Thank u very much on giving me u're time and helping!!

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              The example code I linked you to does work.

              You should always check for null before using. If it's null then obviously the window doesn't exist and isn't opened.

              I know what your problem is though.

              What's happening is you're opening a window and it's called "saveTaskWindow ". Then the user clicks the button again....and you open a window called the "saveTaskWindow " at which time the content in the currently open "saveTaskWindow " is written over.

              If you want more than one window open at a time then you have to give each window a unique name.

              Check if the window exists (if it's not null) and that if it's open. If it does exist and is open, then try a new name for the window...checki ng if a window exists with the new name and if it's open.

              :)

              -Frinny

              Comment

              Working...