Solved

window focus error

Posted on 2003-12-07
22
1,482 Views
Last Modified: 2008-02-01
I have the following code:
WinID = window.open(WinURL,WinTarget,'top=130,left=200,height=' + WinHeight + ',width=' + WinWidth + ',resizable=' + isresize + ',scrollbars=yes,menubar=' + ismenubar + ',toolbar=' + istoolbar + ',directories=no,location=' + islocation + ',status=' + isstatus);  
//WinID.focus();

The problem is that if I press the same link to open the window twice in a row it will not focus the window the second time, once it already has that page loaded in it. When I uncomment the focus line I get the error "Class doesn't support Automation"

any clues to the problem here, or how to get the window to focus everytime, even if you're just loading the same page into it again....
     
0
Comment
Question by:Chris_Granger
22 Comments
 

Author Comment

by:Chris_Granger
ID: 9891832
PS The funtion is being called from within a frame page, if that makes any difference....
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9891987
Here is the code that I use:

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT LANGUAGE=javascript>
<!--
function newWindow(strWin,strURL,intX,intY,intWidth,intHeight){
      strWin =window.open(strURL,strWin,'left=' + intX + ', screenX =' + intX + ', top=' + intY + ', screenY=' + intY + ', width=' + intWidth + ', height=' + intHeight + ', scrollbars=yes, toolbar=yes');
      strWin.focus();
}

//-->
</SCRIPT>

</HEAD>
<BODY>
<form>
<a href=# onClick="newWindow('wndFairCon','http://www.FairfieldConsulting.com',200,0,700,600);return false;">The guy who wrote this</a>
<form>
</BODY>
</HTML>
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9891989
Now what you will want to do is to check to see if the window already exists:

if(strWin){
   strWin.focus();
}

FtB
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9892010
>>Now what you will want to do is to check to see if the window already exists:
 you will also need to ensure that the window has not closed, if (strWin) will check that the window was opened and then allow you to set focus but strWin will also detemine true even if strWin was set and the window has been closed

if(strWin && !strWin.closed){
   strWin.focus();
}
0
 

Author Comment

by:Chris_Granger
ID: 9892259
I've tried these and I still get this error. There must be something obvious worng with my code for it to keep coming up with this error: class does not support automation. If I leave the focus out it works fine but of course, doesn't focus the window... Here's the code:

function NewWindow1(WinURL,WinTarget,WinWidth,WinHeight,isresize,ismenubar,istoolbar,islocation,isstatus){      
var WinID = window.open(WinURL,WinTarget,'top=130,left=200,height=' + WinHeight + ',width=' + WinWidth + ',resizable=' + isresize + ',scrollbars=yes,menubar=' + ismenubar + ',toolbar=' + istoolbar + ',directories=no,location=' + islocation + ',status=' + isstatus);  
WinID.focus();
}


<a  class="navs"  HREF="JavaScript:NewWindow1('termsmain.asp?spage=1#sec','terms','650','460','no','no','no','no','no')">secure payment service.</a>

cheers!
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9892289
<a  class="navs"  HREF="javascript:NewWindow1('termsmain.asp?spage=1#sec','terms','650','460','no','no','no','no','no');return false;">secure payment service.</a>


Fritz the Blank
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9892302
Sorry, forget that.

This seems to work...

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT LANGUAGE=javascript>
<!--
function NewWindow1(WinURL,WinTarget,WinWidth,WinHeight,isresize,ismenubar,istoolbar,islocation,isstatus){    
      var WinID = window.open(WinURL,WinTarget,'top=130,left=200,height=' + WinHeight + ',width=' + WinWidth + ',resizable=' + isresize + ',scrollbars=yes,menubar=' + ismenubar + ',toolbar=' + istoolbar + ',directories=no,location=' + islocation + ',status=' + isstatus);  
      WinID.focus();
}

//-->
</SCRIPT>


</HEAD>
<BODY>

<a HREF="javascript:NewWindow1('termsmain.asp?spage=1#sec','terms','650','460','no','no','no','no','no');" class="navs"  >secure payment service.</a>


</BODY>
</HTML>


FtB
0
 

Author Comment

by:Chris_Granger
ID: 9892336
Still getting a "class doesn't support automation" error when it pops up - linking to the "focus" line. Without that again, no error but no focus.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9892371
The problem may be in the pop up itself? When I run the code here, I get the popup with focus, but of course the pop up is empty since I don't have access to your page...

FtB
0
 

Author Comment

by:Chris_Granger
ID: 9892399
I still get it with just the above code when the popup isn't there (blank page), maybe it's a sensitive script alert setting I have IE set on?
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9892404
May I see your link as you are using it now?

FtB
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:Chris_Granger
ID: 9892438
here it is, I've cut everything I can out of it and I still get the error when the popup opens - whether I use my popup page or another, something freaky is going on (I even restarted my machine...):

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT LANGUAGE=javascript>
<!--
function NewWindow1(WinURL,WinTarget,WinWidth,WinHeight,isresize,ismenubar,istoolbar,islocation,isstatus){    
     WinID = window.open(WinURL,WinTarget);  
     WinID.focus();
}

//-->
</SCRIPT>


</HEAD>
<BODY>

<a HREF="javascript:NewWindow1('termsmain.asp?spage=1#sec','terms','650','460','no','no','no','no','no');">secure payment service.</a>


</BODY>
</HTML>
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9892473
I just changed the URL, and it works fine here:

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT LANGUAGE=javascript>
<!--
function NewWindow1(WinURL,WinTarget,WinWidth,WinHeight,isresize,ismenubar,istoolbar,islocation,isstatus){    
     WinID = window.open(WinURL,WinTarget);  
     WinID.focus();
}

//-->
</SCRIPT>


</HEAD>
<BODY>

<a HREF="javascript:NewWindow1('http://www.fairfieldConsulting.com','terms','650','460','no','no','no','no','no');">secure payment service.</a>


</BODY>
</HTML>



FtB
0
 

Author Comment

by:Chris_Granger
ID: 9892480
It only occurs in my testing environment I have discovered...  Something in iis I wonder?
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9892503
If you like, I could post this page on my site so that you can test.

FtB
0
 

Author Comment

by:Chris_Granger
ID: 9893794
cool, that would help eliminate some issues...

Cheers
0
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 50 total points
ID: 9896182
Here you go:

www.FairfieldConsulting.com/Chris.htm

It seems to be ignoring the size attributes but it works.

FtB
0
 

Author Comment

by:Chris_Granger
ID: 9897610
I get no error at the moment but it doesn't bring the already open window to the fore-front when the link is clicked again.

I think my error problem is caused by a dodgy IE...

Cheers
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9897660
Try adding this to your pop up:

window.onBlur=focus();

FtB
0
 

Author Comment

by:Chris_Granger
ID: 9897763
that would force it toi the front all the time wouldn't it? I just want it to come to forefront when the link is clicked...
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9897855
Nevermind, then.

FtB
0
 

Expert Comment

by:DanielsRJE
ID: 10916563
I recently ran into the same problem: I'm using a "windowtricks.js" with a few standard routines for a long time now, and all of a sudden I was receiving these "Class doesn't support automation" errors on window.focus() lines. Only in IE, FireFox doesn't seem to care much.
I think it has something to do with one of the many hotfixes that have come out of the MS Headquarters (I had not updated my comp for a while, I'm behind a thorough fire wall etc).

In the end solved it by leaving the focus command out of the page that is opening the window, instead adding it to the new page being loaded into the new window, adding onLoad="javascript:window.focus()" tp the body tag. This shuts up IE very nicely ;-)

Richard
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now