By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,472 Members | 1,219 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,472 IT Pros & Developers. It's quick & easy.

knowing when a htmlpage is opened

P: 12
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
Sep 3 '09 #1
Share this Question
Share on Google+
6 Replies


P: 12
my code is: (I added another row)
Expand|Select|Wrap|Line Numbers
  1. var taskWindow = window.open("", "viewTaskWindow");
  2. taskWindow.document.write(taskListTable);
Sep 3 '09 #2

gits
Expert Mod 5K+
P: 5,390
you could use the window's closed property to identify wheter the window is opened already ...

kind regards
Sep 3 '09 #3

P: 12
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.
Sep 3 '09 #4

Frinavale
Expert Mod 5K+
P: 9,731
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.
Sep 3 '09 #5

P: 12
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!!
Sep 4 '09 #6

Frinavale
Expert Mod 5K+
P: 9,731
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
Sep 4 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.