Link to home
Start Free TrialLog in
Avatar of Hillas
Hillas

asked on

Closing a browser window from Flash

How do I close a pop-up window with a specific name from a button click in the parent window. Thnaks for the help.
Avatar of rootdir
rootdir

If you are creating popup using javascript function then
this javascript function will be there in your parent window head.

<SCRIPT LANGUAGE="JavaScript">

var newwin;

function launchwin(winurl,winname,winfeatures)
{
     newwin = window.open(winurl,winname,winfeatures);
     if(javascript_version > 1.0)
     {
           setTimeout('newwin.focus();',250);
     }
}

// add this function to close newly popup window from parent or flash

function closewin()
{
       if (!newwin.closed)
            newwin.close();
}
</SCRIPT>

Call closewin function from flash button like this

on (press, release) {
     getURL("javascript:closewin();");
}

If you have multiple popups then Fill array with unique instace name for each popup. And pass that unique id to closewin function.

This will help you lot. I have created sample for you, If you want post your email

Cheers
RootDir
In the HTML where also the Flash object is put you can place the following Javascript:

<script language="JavaScript">
<!--
function openwin()
{
 myWindow = window.open('test.html','winname','width=190,height=210');
}
function closewin()
{
myWindow.close();
}
// -->
</script>

--------
With the above Javascript you assign the name 'myWindow' to the opened window. This way you can use this name to control the object (also move it, etc).

With the function closewin() you then close the window 'myWindow'.

If you have more windows, just give them different names.


In flash the following actionscript would be used:
on (release) {
    getURL ("javascript:openwin();");
}

To open the window.

on (release) {
    getURL ("javascript:closewin();");
}

To close the window again.

Hope this helps!
oeps posted my answer just too late, did not see the answer from rootdir... sorry
Avatar of Hillas

ASKER

Thanks for the help rootdir.

I need some clarification if you don't mind.

Below is the JavaScript that I am using to open and close pop-up windows. Unfortunately, this only closes the most recently opened window. I can't seem to get it to close a specific window (a window called "Images" for instance.)



<SCRIPT LANGUAGE=JavaScript>

function openNewWindow(URLtoOpen, windowName, windowFeatures) {

  newWindow=window.open(URLtoOpen, windowName, windowFeatures);

}
function closewin()
{
  newWindow.close();
}

</SCRIPT>



Thanks again.

Avatar of Hillas

ASKER

Thanks as well dutchfoxer.
ASKER CERTIFIED SOLUTION
Avatar of rootdir
rootdir

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial