Closing a window opened in a frame

G

Garg

Hi,

I am facing a problem while trying to close a window that I've opened
in a frame.
I am using javascript to close my current popup window. I have written
the following line of code on click of OK button event.

Response.Write("<script> window.close();</script>")

Now the problem is since this window is closed, the frame is still
there and hence, on click of Ok button I get directed to the error
page. I am simply clueless where my control goes when I press OK
button. It just redirects me to the error page.

While debugging, I tried another thing. Right below the above
statement, I added another line of code, i.e.,

Response.Write("<script> window.close();</script>")
Response.Redirect("Home.aspx")

Now with this code in the OK button event handler, when I clicked on
OK button, my current aspx page clsoed and new page (i.e. Home.aspx)
appeared in the frame.
So, it means when I am just writing the first line of code
( Response.Write("<script> window.close();</script>")), at that time
error is, perhaps, because my frame is still open and has nothing to
display.... Dont know... :(

How do I overcome this problem?? Please help....

Thanks
Shivani
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Garg said:
Hi,

I am facing a problem while trying to close a window that I've opened
in a frame.
I am using javascript to close my current popup window. I have written
the following line of code on click of OK button event.

Response.Write("<script> window.close();</script>")

Now the problem is since this window is closed, the frame is still
there and hence, on click of Ok button I get directed to the error
page. I am simply clueless where my control goes when I press OK
button. It just redirects me to the error page.

The window object referes to the frame in this case, not the window that
contains the frame.

Use window.top to get the window object of the page where the frameset is:

window.top.close();
While debugging, I tried another thing. Right below the above
statement, I added another line of code, i.e.,

Response.Write("<script> window.close();</script>")
Response.Redirect("Home.aspx")

This will remove the script tag that you written to the page, and
instead output a redirection page to the frame. The redirection page
will take you to Home.aspx.
Now with this code in the OK button event handler, when I clicked on
OK button, my current aspx page clsoed and new page (i.e. Home.aspx)
appeared in the frame.

No, the current page is not closed, it's just replaced by the new page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top