Connecting Tech Pros Worldwide Forums | Help | Site Map

knowing when a htmlpage is opened

Newbie
 
Join Date: Jul 2008
Posts: 12
#1: Sep 3 '09
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:
Expand|Select|Wrap|Line Numbers
  1. var taskWindow = window.open("", "viewTaskWindow");
  2.  
Thanks

Newbie
 
Join Date: Jul 2008
Posts: 12
#2: Sep 3 '09

re: knowing when a htmlpage is opened


my code is: (I added another row)
Expand|Select|Wrap|Line Numbers
  1. var taskWindow = window.open("", "viewTaskWindow");
  2. taskWindow.document.write(taskListTable);
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,136
#3: Sep 3 '09

re: knowing when a htmlpage is opened


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

kind regards
Newbie
 
Join Date: Jul 2008
Posts: 12
#4: Sep 3 '09

re: knowing when a htmlpage is opened


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:

Expand|Select|Wrap|Line Numbers
  1. taskListTable = xml.transformNode(xsl);
  2. var taskWindow = window.open("", "saveTaskWindow");
  3. taskWindow.document.write(taskListTable);
i can't ask about the window because i open it right away.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,182
#5: Sep 3 '09

re: knowing when a htmlpage is opened


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.
Newbie
 
Join Date: Jul 2008
Posts: 12
#6: Sep 4 '09

re: knowing when a htmlpage is opened


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!!
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,182
#7: Sep 4 '09

re: knowing when a htmlpage is opened


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...checking if a window exists with the new name and if it's open.

:)

-Frinny
Reply