Connecting Tech Pros Worldwide Forums | Help | Site Map

Check if a window is open

Jack
Guest
 
Posts: n/a
#1: Mar 16 '06
I have a main webpage that has a list of records, each with a link to a
window.open function call. As an example, a page that opens is
editrecord.aspx?RecordID=34, and another is
editrecord.aspx?RecordID=52. If the user starts changing the contents
of the opened window, and then leaves it open and goes back to the main
page, refreshes the list, and clicks on the same record link again, it
reloads the contents of the page the user had changed, and all the
changes they made are lost. Is there a way to check to see if the
window for that record is open before we reload it, so that I can just
call the focus() function on that window instead of window.open again?


Erwin Moller
Guest
 
Posts: n/a
#2: Mar 17 '06

re: Check if a window is open


Jack wrote:
[color=blue]
> I have a main webpage that has a list of records, each with a link to a
> window.open function call. As an example, a page that opens is
> editrecord.aspx?RecordID=34, and another is
> editrecord.aspx?RecordID=52. If the user starts changing the contents
> of the opened window, and then leaves it open and goes back to the main
> page, refreshes the list, and clicks on the same record link again, it
> reloads the contents of the page the user had changed, and all the
> changes they made are lost. Is there a way to check to see if the
> window for that record is open before we reload it, so that I can just
> call the focus() function on that window instead of window.open again?[/color]

Hi,

Every window you create with JS will exist as reference, even if it is
closed already, so testing for a windowref will not help.

BUT: Every window has a property (read-only) called 'closed'.
If this is set to true: window is closed, else it is still open.

if (mywindowref.closed){
// window closed, reopen it
...your code

} else {
// window open, focus to it.
....
}

Regards,
Erwin Moller
Closed Thread


Similar JavaScript / Ajax / DHTML bytes