473,394 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

focus a window - how to

Hi,

I'm an absolute beginner with JavaScript.
Say, I am in a window which I call WinA
There I have
<script>
var WinA=self
</script>
Later on, while a different window ("WinB") is focused, I tried
<script>WinA.focus()</script>

but it doesn't give focus to the previous Window (WinA).

Are variables in JavaScript "global" or local to a given
window. ( If yes, are there global variables? )

Sorry, if this is a too dumb a question.

Many thanks for your help,
Helmut.

--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
Aug 14 '07 #1
4 1586
Helmut Jarausch wrote:
Hi,

I'm an absolute beginner with JavaScript.
Say, I am in a window which I call WinA
There I have
<script>
var WinA=self
</script>
Later on, while a different window ("WinB") is focused, I tried
<script>WinA.focus()</script>
My guess is that javascript complains that WinA is unknown?
(Check in firefox the javascriptconsole)

>
but it doesn't give focus to the previous Window (WinA).

Are variables in JavaScript "global" or local to a given
window. ( If yes, are there global variables? )
They are global to the window they live in.
The good news is that you CAN communicate between windows.
The URLs in both windows MUST be in the same domain for this to work.

example:
you only have WinB.
You open WinA from WinB, like this:

var myWinAreference =
window.open("http://www.example.com/test.html","WinA");

Now you have a variable named myWinAreference in your WinB.

You can use this myWinAreference to address WinA, eg:
myWinAreference.sayHi();
will call a function sayHi() in WinA.

or:

myWinAreference.focus();

Hope that helps.
Regards,
Erwin Moller
>
Sorry, if this is a too dumb a question.
No such thing as a dumb questions. Dumb answers however... ;-)

>
Many thanks for your help,
Helmut.
Aug 14 '07 #2
Erwin Moller wrote:
Helmut Jarausch wrote:
>Hi,

I'm an absolute beginner with JavaScript.
Say, I am in a window which I call WinA
There I have
<script>
var WinA=self
</script>
Later on, while a different window ("WinB") is focused, I tried
<script>WinA.focus()</script>

My guess is that javascript complains that WinA is unknown?
(Check in firefox the javascriptconsole)

>>
but it doesn't give focus to the previous Window (WinA).

Are variables in JavaScript "global" or local to a given
window. ( If yes, are there global variables? )

They are global to the window they live in.
The good news is that you CAN communicate between windows.
The URLs in both windows MUST be in the same domain for this to work.

example:
you only have WinB.
You open WinA from WinB, like this:

var myWinAreference =
window.open("http://www.example.com/test.html","WinA");

Now you have a variable named myWinAreference in your WinB.

You can use this myWinAreference to address WinA, eg:
myWinAreference.sayHi();
will call a function sayHi() in WinA.

or:

myWinAreference.focus();
Thanks for your help. I fear I've a more complicated situtation.

On my initial page I have
<frameset rows="60%,*">
<frame src="Quest.pih" name="Questionnaire">
<frame src="empty.html" name="help">
</frameset>
in Quest.pih <form method="post" action="Search.ks/Show" target="Results">
where there is no frame with name "Results", yet. So my browser
opens a new one. There I want a button "new question" which gives
focus to the previous page which contains the frame "Questionnaire".

So, the window opening is implicit! What can I do?

Many thanks,
Helmut.
--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
Aug 14 '07 #3
Helmut Jarausch wrote:
in Quest.pih <form method="post" action="Search.ks/Show" target="Results">
where there is no frame with name "Results", yet. So my browser
opens a new one. There I want a button "new question" which gives
focus to the previous page which contains the frame "Questionnaire".

So, the window opening is implicit!
If it even happens.
What can I do?
For example:

<script type="text/javascript">
function submitPopup(f)
{
var w = window.open(f.action, f.target, "...");
f.submit();
return !!w;
}
</script>

<form method="post" action="Search.ks/Show" target="Results"
onsubmit="return !submitPopup(this);">

This presumes that the window name is available right after window.open()
was called; however, that operation is performed by the AOM and so
asynchronously. Using a timeout before submitting the form might be
necessary, although not entirely reliable as well.
HTH

PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Aug 14 '07 #4
Thomas 'PointedEars' Lahn wrote:
Erwin Moller wrote:
<snip>
>>Sorry, if this is a too dumb a question.
No such thing as a dumb questions. Dumb answers however... ;-)

Indeed ;-)
LOL. I really asked for that. ;-)
Thanks for correcting though.

Regards,
Erwin Moller
>
PointedEars
Aug 14 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fred Snider | last post by:
Help! Opening a new window using the window.open( ) command works great for opening new windows and having them on top and having the focus. The window.focus command brings any existing...
9
by: Randell D. | last post by:
Folks, I'm working on a contact name/address database whereby a slimed down list is shown in the main window. When a record is selected, the complete record is displayed in a new window via a...
1
by: Robert Dickow | last post by:
Here's an interesting problem: When Netscape Nav plays an embedded sound, the current window will lose focus. Specifically, a user may be typing into a text input field, but an embedded sound in...
1
by: Barry Svee | last post by:
I'm struggling with the JavaScript blur event. I have an activex control that I need to interact with when a window loses focus, namely to instruct it to give up control of a barcode scanner so...
31
by: Benno Bös | last post by:
If I use the following construct in the frame "main" for a link to an extern site: <A HREF="http://www.any.xy" TARGET="extern"> the Browser is creating the window "extern", loading the page...
4
by: Csaba Gabor | last post by:
Up until a few weeks ago, javascript code like window.open("http://mydomain.com", "windowName"); would always bring my new or reused window to the top, with focus. Lately, Firefox (Deer park...
11
by: Alex.Svetos | last post by:
Hello, I'm trying to get a popup to keep focus when it is re-clicked. The script below is supposed to produce this exact behaviour, however it doesn't work, at least on firefox 1.0.7 and moz...
4
by: Roger | last post by:
Hi, I am confused about the differences between this.window.focus(), window.focus(), and this.focus(). I want to use the calls in a <body onload="..."tag. What are the differences between...
4
by: Spizzat2 | last post by:
I'm trying to figure out a workaround to a minor annoyance that I'm coming up with while coding a site. I've got some keyboard shortcuts set up for the site via javascript, and when I press escape,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.