Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AS3...Closing browser window in which the SWF is loaded

Community Beginner ,
May 06, 2010 May 06, 2010

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!

TOPICS
ActionScript
9.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 06, 2010 May 06, 2010

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");
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 06, 2010 May 06, 2010

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");
}

image.jpg

I'm using IE7.

Thanks again!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 07, 2010 May 07, 2010

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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 07, 2010 May 07, 2010
LATEST

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...

>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines