Page 1 of 1

closing a window

Posted: Thu Mar 03, 2005 11:24 am
by gurjit
hi all,

i open a window from my parent window like this

window.open('../stationary/x_students_mailshots_csv.php', 'csv_create', 'top=0,left=0,location=1,menubar=0,resizable=0,scrollbars=no,status=0,toolbar=0,width=5,height=5');


the x_students_mailshots_csv.php file has the ob_start(); function for creating an excel file and downloading it on your machine. so when this window opens a download dialogue box appears.

my problem is when the user downloads the created excel file the open window cannot be closed. why?

i used
csv_create.close()
in both parent and child window and it does not work.

Posted: Thu Mar 03, 2005 11:29 am
by Chris Corbyn
You need identify the new window with a variable.

Code: Select all

var newWindow = window.open('../stationary/x_students_mailshots_csv.php', 'csv_create', 'top=0,left=0,location=1,menubar=0,resizable=0,scrollbars=no,status=0,toolbar=0,width=5,height=5'); 



//then to close it

newWindow.close()

Posted: Thu Mar 03, 2005 11:30 am
by feyd
did you save the returned handle from the function?

if so, that's what you ask to close.


Moved to Client-side.

Posted: Thu Mar 03, 2005 11:48 am
by gurjit
does not work.....

got javascript alert 'newWindow undefined'.....

at the bottom of the parent window page i put

<script>
newWindow.close();
</script>

Posted: Thu Mar 03, 2005 12:33 pm
by feyd
did you save the window handle returned as newWindow?

Maybe you should post a link to a live version of this..

Posted: Thu Mar 03, 2005 2:01 pm
by patrikG
no offense, gurjit, but google for it. You'll find tons of examples. The window-object and its open and close-methods have been around probably before ECMA-script became Javascript. ;)