Click to See Complete Forum and Search --> : problem in calling self.focus()


sam2003
10-07-2003, 09:52 AM
I have problem in calling self.focus() on a window which is hidding behind other open browser window. It works fine when window is minimized. If it is hidden not minimized then I see icon flashes at task bar but it does not come to front. Any suggestion why it behave like this?

AdamBrill
10-07-2003, 09:56 AM
That is the proper way for the browser to act. If the user wants to hide the browser, you shouldn't be able to make it keep jumping in front. Basically, there is no way to make it stay in front(or to make it go to the front when it is hidden).

sam2003
10-07-2003, 10:10 AM
Thanks Adam for prompt reply.

My problem is that this window has to show on the front when it receives an event from the backend server so user can take some action otherwise they can miss events.

is there any work around?

thanks again

AdamBrill
10-07-2003, 12:04 PM
The only way is to close the browser and open a new one, which may or may not work for you. Other than that, the best you can do is make it blink like that...

sam2003
10-07-2003, 03:27 PM
Thanks Adam,

but problem is that I can't close the browser, if browser is closed and reopen user has to login again so I guess I have to live with this.

Khalid Ali
10-07-2003, 03:35 PM
reload(true) the page when evern you want the window to comeinfront,

sam2003
10-07-2003, 03:53 PM
Khalid thanx for reply,

I tried but it did not worked , I got logged out of the system, and it did not bring page to the front.

AdamBrill
10-07-2003, 08:01 PM
Originally posted by Khalid Ali
reload(true) the page when evern you want the window to comeinfront, Umm... I seem to have missed something. ;) Unless I'm wrong, that won't do what they want... :)

sam2003, I'm afraid that there really isn't a solution for you(unless Khalid knows of one). The best that you can do is just make it blink in the task bar...

Gollum
10-08-2003, 06:35 AM
That is the proper way for the browser to act

Adam, where does it say that? All the documentation I have says that the window should come to the front - and indeed in IE (at least), it does.

AdamBrill
10-08-2003, 07:46 AM
What version of IE are you using??? It certainly doesn't do that for me... The reason that I stated that that was the "proper way for it to act" was because that is what it does in the new versions of the browsers. In other words, what I was stating was that they didn't have anything wrong in their code, since their code was working "properly".

Webskater
10-08-2003, 08:07 AM
I do this all the time because I do not want people having multiple copies of the same window (containing the same page) open.
I find putting window.focus() in the onload event of the body tag brings the page to the front regardless of whether it is miminised or simply behind other windows. It works every time for me.

sam2003
10-08-2003, 08:51 AM
Hi good morning guys,

thanks for all your replies, answer to Adam:
we are using IE 5.0 to 6.0 on different machines.

Webskater: I tried to put self.focus() in body tag before also but it did not work for me because it is called only first time when page gets loaded (if i am correct) not everytime.

Thing I don't understand is that if it is minimized it works fine and if it is not minimized just behind other windows it does not why??

I am not javascript guru I am just a java developer so can anyone shed some light on this.

thanks again

Webskater
10-08-2003, 09:01 AM
If the server is communicating with your hidden or minimized window it is presumably reloading a page within the window. The onload event is triggered when this happens. You need to put:
<body onload="window.focus();">
to make sure the window gets focus when the onload event occurs.

sam2003
10-08-2003, 11:05 AM
my main file looks like this

<html>
<head>

</head>
<frameset rows="90,*" border="1" frameborder="1">

&nbsp; &nbsp; <frameset cols="500,*">
&nbsp; &nbsp;&nbsp; <frame name="toolbar" src="" marginwidth="0" marginheight="0" scrolling="no" frameborder="1" border=1 noresize>
&nbsp; &nbsp;&nbsp; <frame name="notification" src="" marginwidth="0" marginheight="0" scrolling="auto" frameborder="1" border=1 noresize>
</frameset>

&nbsp; &nbsp; <frame name="main" src="" marginwidth="0" marginheight="0" scrolling="auto" frameborder="1" border=1 noresize>

</frameset>

</html>

when events comes to frame toolbar it reloads main like this
top.main.location.href = "some source"

does it helps to understand the problem?

sam2003
10-08-2003, 11:10 AM
posting again stripping out unnecessary tags

<html>
<head>

</head>
&nbsp;<frameset rows="90,*" border="1" frameborder="1">
&nbsp;&nbsp;&nbsp;<frameset cols="500,*">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<frame name="toolbar" src="" >
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<frame name="notification" src="" >
&nbsp;&nbsp;&nbsp;</frameset>

&nbsp;&nbsp;&nbsp;<frame name="main" src="" >

&nbsp;</frameset>

</html>

Khalid Ali
10-08-2003, 11:29 AM
Originally posted by AdamBrill
.....isn't a solution for you(unless Khalid knows of one).

I hope I have not missed anything,But in case you atill are looking for a solution.

http://www.webapplikations.com/pages/html_js/document/BringWindowToFocus.html

it works for IE6+,NS6+ and opera 7+

Webskater
10-08-2003, 11:37 AM
does it helps to understand the problem?
Not at all. I thought you were having a problem getting a hidden or minimized window to get the focus. You have posted code where one page in a frameset is loading a page in the same frameset??

sam2003
10-08-2003, 11:56 AM
Sorry I am not very clear

code that I posted is one application running in different frames but in same browser window.

now user open other browser windows so my application window hide behind new opened windows

back to my application, when events comes to frame toolbar it reloads main like this
top.main.location.href = "some source"

everything is going on in the same browser window.

all other browser windows opened by user are totally separate and not interacting with my app. but because they are opened after my app window so they are sitting on top

is it clear now :) .

sam2003
10-08-2003, 12:23 PM
Khalid I checked the link that you provided thanks.

is there a way to use following code

var newWin=window.open("","newWin",winProps);

but forces the newWin to open in a targeted frame so now I have a reference to the window and I can call newWin.focus(); to bring whole app window to front.

Is it possible?

AdamBrill
10-08-2003, 12:51 PM
Khalid, unless I'm mistaken, this will only work on a popup window, not on the original window. Am I correct? If so, I'm not sure that that will work for him...

Travman
10-08-2003, 02:42 PM
One thing you could try is to write a script that forces the page to reload after a specified interval, then if the <body onload="window.focus();"> tag is present, the reload script may cause the window to come to the front? I don't know the reload code, but the question to ask is what is the maximum interval you're willing to wait before it reloads. 1 minute? 30 seconds? It could get annoying for users that don'thave it minimised.

Khalid Ali
10-08-2003, 03:08 PM
Originally posted by AdamBrill
Khalid, unless I'm mistaken,

You are absolutely correct Adam,it will work only if a child window is opened from within the parent