render :js => "window.close();" wont work

when i try to do the following in a action

render :js => “window.close();” wont work

it still response in the browser,but the window wont close.

i dont know why.thx!

when i try to do the following in a action render :js => "window.close();" wont work

it still response in the browser,but the window wont close. i dont know why.thx!

You can only close a window in JavaScript if you also opened it in JavaScript. So this will work on a popup window you opened, but it won't work on a window the user opened. Which is yours? Also, some browsers further kink this so that the window.close() event will only work if it was fired from a user click, not a JavaScript program running on its own without user interaction.

Walter

thx very much. so is there any ways to accomplish that?

在 2012年3月27日 下午11:02,Walter Lee Davis waltd@wdstudio.com写道:

thx very much. so is there any ways to accomplish that?

If you're asking if the page can close the main (or any user-opened) window, the answer is no, and for good reason. The page can close itself if the window was opened programmatically, but it sounds as if you are not talking about doing that, so the answer is no.

Walter

muchas gracias

在 2012年3月27日 下午11:10,Walter Lee Davis waltd@wdstudio.com写道: