Copy link to clipboard
Copied
This would seem like an easy thing to do, and I've found many different code example out there to accomplish this, but none of them work.
Using AS3, and without modifying the published HTML file, I want close the browser window (IE/Firefox) in which my SWF is playing on click of a button. This is not a pop-up window that the SWF is running in. It is the main browser window.
Here's my code:
btn_closeBrowser.addEventListener (MouseEvent.CLICK, close_Browser);
function close_Browser(event:MouseEvent):void
{
var jscommand:String = "window.close();";
var req:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);");
navigateToURL(req, "_self");
}
Nothing happens when I click on btn_closeBrowser in IE or Firefox. But, I do hear the hard drive working each time I click the button, so something is happening.
Any help with this is greatly appreciated!
Copy link to clipboard
Copied
This works in IE and Chrome but I don't think it will ever work in FireFox due to its security restrictions. If you find a way let us know...
btnCloseBrowser.addEventListener(MouseEvent.CLICK, closeBrowser, false, 0, true);
function closeBrowser(e:MouseEvent):void
{
ExternalInterface.call("window.open","","_self");
ExternalInterface.call("window.close");
}
Copy link to clipboard
Copied
Thanks dmennenoh, but still doesn't work; nothing happens in IE. Here's my exact code:
import flash.external.*;
btn_closeBrowser.addEventListener(MouseEvent.CLICK, closeBrowser, false, 0, true);
function closeBrowser(e:MouseEvent):void
{
trace("btn_closeBrowser clicked");
ExternalInterface.call("window.open","","_self");
ExternalInterface.call("window.close");
}

I'm using IE7.
Thanks again!
Copy link to clipboard
Copied
Odd, I tested in IE7 as well - and it worked fine. Not sure what to tell you to try. Maybe just give up on it since it's not going to work in all browsers anyway...
Copy link to clipboard
Copied
I certainly don't want to give up on it...
I've attached the very simple FLA that I'm using to test this code. Can you see if it works on your end? The FLA contains one button "Show" and when clicked, it's supposed to close the browser window. That's it. Very simple. Please let me know what you find out. I'm more concerned about it working in IE than any other browser.
Thanks.
Artur Trzebunia
arturtn@msn.com
Date: Fri, 7 May 2010 05:46:48 -0600
From: forums@adobe.com
To: arturtn@msn.com
Subject: AS3...Closing browser window in which the SWF is loaded
Odd, I tested in IE7 as well - and it worked fine. Not sure what to tell you to try. Maybe just give up on it since it's not going to work in all browsers anyway...
>
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more