After window opened using window.open, how to bring it forward when the same link is clicked

I have a link on a page that is this:

<a href="javascript:void window.open('miniplayer.asp?ID=1','Mini Player','height=200,width=350,status=no,toolbar=no,menubar=no,location=no')">
<img src="/images/1.jpg" width="64" height="48" border="0">
</a>

Using Firefox, when I click on the link, the window appears.  If the window goes behind another window, if the same link is clicked, the window is reloaded (I put an alert in the onload event), but the window does not come forward.  I have tried below which does not work in Firefox, but it does using IE7:

onload="window.focus()"

  Any suggestions?


LVL 3
onemorecokeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
Try this:
<a href="javascript:void if(window.MiniPlayer){window.MiniPlayer.focus();}else{window.MiniPlayer = window.open('miniplayer.asp?ID=1','MiniPlayer','height=200,width=350,status=no,toolbar=no,menubar=no,location=no')}">
<img src="/images/1.jpg" width="64" height="48" border="0">
</a>

Open in new window

0
onemorecokeAuthor Commented:
Thanks for the response.  I get a javascript error 'window.MiniPlayer' is nul or not an object.  What do you think?
0
hieloCommented:
Try this:
<script type="text/javascript"><!--
window.MiniPlayer=null;
function handleClick()
{
	if(null!==window.MiniPlayer){
		window.MiniPlayer.focus();
	}
	else
	{
		window.MiniPlayer = window.open('miniplayer.asp?ID=1','MiniPlayer','height=200,width=350,status=no,toolbar=no,menubar=no,location=no');
	}
return false;
}
//--></script>
<a href="#" onclick="return handleClick();">
<img src="/images/1.jpg" width="64" height="48" border="0">
</a>

Open in new window

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

hieloCommented:
Here's a better implementation. On this example the link's href value is passed to the javascript function and the function uses that to open the popup window.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<script type="text/javascript"><!--
window.MiniPlayer=null;
function handleClick(url)
{
	if(null!==window.MiniPlayer){
		window.MiniPlayer.focus();
	}
	else
	{
		window.MiniPlayer = window.open(url,'MiniPlayer','height=200,width=350,status=no,toolbar=no,menubar=no,location=no');
	}
return false;
}
//--></script>
<a href="miniplayer.asp?ID=1" onclick="return handleClick(this.href);" style="background-color:red;">
<img src="/images/1.jpg" width="64" height="48" border="0">
</a>
</body>
</html>

Open in new window

0
onemorecokeAuthor Commented:
Thanks for the insight, I had to rewrite it a bit:

href="javascript:if(MiniPlayer){MiniPlayer.focus()}else{var MiniPlayer=window.open('miniplayer.asp?=1','MiniPlayer','height=200,width=350,status=no,toolbar=no,menubar=no,location=no');}"

I had to get rid of the "window." and make MiniPlayer an object before I did not get any errors.  The problem with this code though is that if the window does get close and you click on the link again, you get the error:

"The callee (server) is not available and disappeared; all connections are invalid, The call did not execute."

This would make sense because the object is no longer connected to anything.  I am trying to find out a way to see if he object is gone and reset things.  Possibly with a try/catch.
0
hieloCommented:
Here you go:
Notice that I got rid of 'var' in the else clause and I am also using the onclick event handler. If you use the href to execute the code, when you click on the the browser window will change
<a href="javascript:void()" onclick="if(MiniPlayer && false===MiniPlayer.closed){MiniPlayer.focus()}else{MiniPlayer=window.open('miniplayer.asp?=1','MiniPlayer','height=200,width=350,status=no,toolbar=no,menubar=no,location=no');};return false;">T</a>

Open in new window

0
onemorecokeAuthor Commented:
If I remove the var, I get Miniplayer is undefined error.
0
onemorecokeAuthor Commented:
Ok, I got it working.  I had to include the var or it did not work.  Also, I was able to just use what you sent and put it into the href alone.  The MiniPlayer.closed was the key.  I also change the logic to !Miniplayer.closed

Thanks for you input, it really helped.
<a href="javascript:if(MiniPlayer && !MiniPlayer.closed){MiniPlayer.focus()}else{var MiniPlayer=window.open('miniplayer.asp?ID=1%>','MiniPlayer','height=200,width=350,status=no,toolbar=no,menubar=no,location=no');}">

Open in new window

0
hieloCommented:
That's because MiniPlayer needs to be declared first. That's what I did on post http:#20793887 within the <script> tag. Refer to the complete example below.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
	var MiniPlayer=null;
</script>
 
</head>
<body>
<a href="javascript:void()" onclick="if(MiniPlayer && false===MiniPlayer.closed){MiniPlayer.focus()}else{MiniPlayer=window.open('miniplayer.asp?=1','MiniPlayer','height=200,width=350,status=no,toolbar=no,menubar=no,location=no');};return false;">Test</a> 
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
onemorecokeAuthor Commented:
Ok, thank you, that makes sense.  I have never seen:

false===

before.  Is that valid?

0
hieloCommented:
>>I have never seen: "false=== ..." before. Is that valid?
Absolutely. To clarify its usage consider this:
var x = 0;

//this will alert true because 0 evaluates to false in boolean context
alert (x==false);

//this will alert  false because false is a boolean object, but x in a Number object
//even though x evaluates to false, it is NOT the same object type as false
alert(x===false);
0
onemorecokeAuthor Commented:
Thank you for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.