473,585 Members | 2,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting focus to window

I want to use a second window to link to and put new content in it and pop
up is some link is clicked. How to set the focus to the second window if
it's already open. With what I do now, the window stays below my main
window.
Jul 20 '05 #1
9 8709
"Guus Ellenkamp" <el************ @wolmail.nl> writes:
I want to use a second window to link to and put new content in it and pop
up is some link is clicked. How to set the focus to the second window if
it's already open. With what I do now, the window stays below my main
window.


I would use a function like

function winOpenFocus(ur l,name,config) {
var w = window.open(url ,name,config);
w.focus();
return w;
}

and then use that where you use window.open now.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
Thanks for the reply, but it doesn't work. I'm working with Dreamweaver.
This is the code I get:

<td width="21%" align="center" height="14"><fo nt face="Arial, Helvetica,
sans-serif"><b><a href="http://www.abnamro.com "
onClick="MM_cal lJS('CompanyWin dowHandle =
winOpenFocus(\' http://www.abnamro.com \',\'GE_Company \',\'\');')"
target="GE_Comp any">ABN-AMRO</a></b></font></td>
"Lasse Reichstein Nielsen" <lr*@hotpop.com > schreef in bericht
news:ad******** **@hotpop.com.. .
"Guus Ellenkamp" <el************ @wolmail.nl> writes:
I want to use a second window to link to and put new content in it and pop up is some link is clicked. How to set the focus to the second window if
it's already open. With what I do now, the window stays below my main
window.


I would use a function like

function winOpenFocus(ur l,name,config) {
var w = window.open(url ,name,config);
w.focus();
return w;
}

and then use that where you use window.open now.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #3
I think I found the solution myself: the window name may not contain
underscores.

"Guus Ellenkamp" <el************ @wolmail.nl> schreef in bericht
news:bi******** **@reader1.tisc ali.nl...
Thanks for the reply, but it doesn't work. I'm working with Dreamweaver.
This is the code I get:

<td width="21%" align="center" height="14"><fo nt face="Arial, Helvetica,
sans-serif"><b><a href="http://www.abnamro.com "
onClick="MM_cal lJS('CompanyWin dowHandle =
winOpenFocus(\' http://www.abnamro.com \',\'GE_Company \',\'\');')"
target="GE_Comp any">ABN-AMRO</a></b></font></td>
"Lasse Reichstein Nielsen" <lr*@hotpop.com > schreef in bericht
news:ad******** **@hotpop.com.. .
"Guus Ellenkamp" <el************ @wolmail.nl> writes:
I want to use a second window to link to and put new content in it and pop up is some link is clicked. How to set the focus to the second window if it's already open. With what I do now, the window stays below my main
window.


I would use a function like

function winOpenFocus(ur l,name,config) {
var w = window.open(url ,name,config);
w.focus();
return w;
}

and then use that where you use window.open now.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'


Jul 20 '05 #4
You need to return false from the onclick event, otherwise the HREF will be
followed and the default behaviour of the browser will take precedence.

<a href="http://www.abnamro.com "
onClick="MM_cal lJS('CompanyWin dowHandle =
winOpenFocus(\' http://www.abnamro.com \',\'GE_Company \',\'\');');ret urn false;"
target="GE_Comp any">ABN-AMRO</a>

Guus Ellenkamp wrote:
Thanks for the reply, but it doesn't work. I'm working with Dreamweaver.
This is the code I get:

<td width="21%" align="center" height="14"><fo nt face="Arial, Helvetica,
sans-serif"><b><a href="http://www.abnamro.com "
onClick="MM_cal lJS('CompanyWin dowHandle =
winOpenFocus(\' http://www.abnamro.com \',\'GE_Company \',\'\');')"
target="GE_Comp any">ABN-AMRO</a></b></font></td>

"Lasse Reichstein Nielsen" <lr*@hotpop.com > schreef in bericht
news:ad******** **@hotpop.com.. .
"Guus Ellenkamp" <el************ @wolmail.nl> writes:
I want to use a second window to link to and put new content in it and pop up is some link is clicked. How to set the focus to the second window if
it's already open. With what I do now, the window stays below my main
window.


I would use a function like

function winOpenFocus(ur l,name,config) {
var w = window.open(url ,name,config);
w.focus();
return w;
}

and then use that where you use window.open now.

/L


--
| Grant Wagner <gw*****@agrico reunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #5
DU
Guus Ellenkamp wrote:
I think I found the solution myself: the window name may not contain
underscores.


Nah... Window name can contain underscores. That's not your problem
really. You need to use a global variable to store the returned window
object reference and then make a focus() call if the window exists but
has not been closed.

I discussed your issue at this precise url:

http://www10.brinkster.com/doctorunc...seLowerSetting

There is an interactive demo in that page. Just look for the code.

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html

Jul 20 '05 #6
DU <dr*******@hotR EMOVEmail.com> writes:
His window object reference needs to be a global variable, otherwise
it's pretty useless.
I am not sure I understand what the problem is. Can you explain in
more detail?

If he tries to open a page a second time with the same name, the page
will just open in the same window, and it will gain focus. I see no
need for a global variable.
Working example at:
http://www10.brinkster.com/doctorunc...pera7Bugs.html
See function OpenRequestedPo pup(strUrl) in the source code.


I made the WindowObjectRef erence a local variable and removed all the
tests for it already existing ... and it still worked the same. The
only difference is that now it doesn't check whether you are asking
for the same URL twice.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #7
DU
Lasse Reichstein Nielsen wrote:
DU <dr*******@hotR EMOVEmail.com> writes:

His window object reference needs to be a global variable, otherwise
it's pretty useless.

I am not sure I understand what the problem is. Can you explain in
more detail?

If he tries to open a page a second time with the same name, the page
will just open in the same window, and it will gain focus. I see no
need for a global variable.

Working example at:
http://www10.brinkster.com/doctorunc...pera7Bugs.html
See function OpenRequestedPo pup(strUrl) in the source code.

I made the WindowObjectRef erence a local variable and removed all the
tests for it already existing ... and it still worked the same. The
only difference is that now it doesn't check whether you are asking
for the same URL twice.

/L


Then it deletes the previous window, then re-creates and re-opens it
again which is a very poor usage of user system resources.
In your function
function winOpenFocus(ur l,name,config) {
var w = window.open(url ,name,config);
w.focus();
return w;
}

this is what happens if the window with the same url already exists.
DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html

Jul 20 '05 #8
DU <dr*******@hotR EMOVEmail.com> writes:
Then it deletes the previous window, then re-creates and re-opens it
again which is a very poor usage of user system resources.
It shouldn't need to reopen it.
In your function
function winOpenFocus(ur l,name,config) {
var w = window.open(url ,name,config);
w.focus();
return w;
}

this is what happens if the window with the same url already exists.


If a window with the same name already exists, the url is opened into
this window. The page is reloaded, even if a page with the same url is
already in it, that is true, but the window is not recreated. It is
reused.

Whether it is important not to reload the same URL, that is a
different problem, that the original poster didn't mention (and that I
honestly hadn't though about). To prevent this, you do need to keep
a copy of the URL around, either as a global variable, or as a local
static variable.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #9
DU
Lasse Reichstein Nielsen wrote:
DU <dr*******@hotR EMOVEmail.com> writes:

Then it deletes the previous window, then re-creates and re-opens it
again which is a very poor usage of user system resources.

It shouldn't need to reopen it.

In your function
function winOpenFocus(ur l,name,config) {
var w = window.open(url ,name,config);
w.focus();
return w;
}

this is what happens if the window with the same url already exists.

If a window with the same name already exists, the url is opened into
this window. The page is reloaded, even if a page with the same url is
already in it, that is true, but the window is not recreated. It is
reused.


Thank you for correcting me on this. Yes. The document is reloaded but
the window is not recreated.
Whether it is important not to reload the same URL, that is a
different problem, that the original poster didn't mention (and that I
honestly hadn't though about). To prevent this, you do need to keep
a copy of the URL around, either as a global variable, or as a local
static variable.

/L


DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html

Jul 20 '05 #10

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

Similar topics

3
7401
by: Jesper Dannemamm | last post by:
Hi I am having trouble setting focus on I tried using this script in the usercontrol's page_load sub to set focus on a textbox with the ID = "user_name": Page.RegisterStartupScript("focus", "<script language=""JavaScript"">document.getElementById.user_name.focus();</script> ")
20
12286
by: Arne | last post by:
During testing <div style="overflow:auto;"> in CSS I noticed the mousewheel would work in Mozilla only after I made a <a href="#">some text</a> link and clicked on that, within the div. It appears as if Mozilla needs to have the focus set on that div in order for the mousewheel to work. That's all that link does. The mousewheel works...
0
1760
by: Shravan | last post by:
Hi, I have a Windows Forms Custom DataGrid, which is put in a usercontrol, which on setting DataSource is setting focus to grid. The call stack for setting the focus is as follows. This is not happened always whenever DataSource is set, only called sometimes, in a series of setting DataSource, I could get this setting focus only one time ....
2
7397
by: Mystery Man | last post by:
We have an MDI application that is not setting always setting focus to the newly corrected MDI. It is creating the form and it is the topmost but it does not have focus. The code we are using to activate the MDI is something like the following: frmTest frm = new frmTest(); frm.MdiParent = this; frm.Show();
3
8307
by: Steve Yerkes | last post by:
There seems to be way too much confusion over how to set focus on the a field using a field validator. I looked all over the web and found people trying to do this, but not getting anywhere. There are a couple of people selling components... but that is not really an option for me... So, I took the plunge and modified the "WebUIValidation.js"...
1
1783
by: reidarT | last post by:
I have a webform and found some code where I understand some of it, but not all The code is as follows public static void SetFocus(Control control) { StringBuilder sb = new StringBuilder(); sb.Append("\r\n<script language='JavaScript'>\r\n"); sb.Append("<!--\r\n"); sb.Append("function SetFocus()\r\n");
3
1654
by: register_allocation | last post by:
I have a frameset where I call a JavaScript function in the onLoad method: .... <frameset cols="..." onLoad="setFn()"> ... <frame name="data_frame" ...> </frameset> In setFn, I am dynamically loading the contents of the 'data_frame', which works fine. I then want to set focus to the 'data_frame':
1
1233
by: sam needs help | last post by:
Hi , I would want set the focus in a webpage ..not on any specific fields...but on the page in general.Is this possible using javascript as document.focus,window.focus doesn't work . If i give self.focus in body onload , it works but it doesnt suit my application .Can anyone help . Thanks .
8
2133
by: Brad Isaacs | last post by:
Good morning friends, I am working with Visual Studio 2005, ASP.NET 2.0 I am working with the Login controls provided my .NET 2.0, trying to make the Login1 control UserName textbox obtain SetFocus upon load of the .aspx web page but I cannot for the life of me get this to work. I tried using the defaultfocus on the Form but that did not...
3
2152
by: kelvin.koogan | last post by:
I have a number of controls on a tab page. I want to validate them all when the user tries to leave the tab. I then want to highlight the first control which fails validation. How can I do this? I try setting focus but something seems to set the focus back to the control which had it before validation. Any ideas? TIA, KK
0
7908
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8336
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8212
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5389
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3835
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2343
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.