473,230 Members | 1,840 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,230 software developers and data experts.

focus() not working in IE when created by appendChild

I have a main window and a menu window.
The menu window is opened from the main window by clicking on "Open Menu".
A google window can also be opened from the main window by clicking "Open Google". If "google_win" is clicked on in the menu window the google window is focused on.

Now if "Add Google to Menu" is clicked in the main window, another line is written to the menu window also saying "google_win".
This second "google_win" is added by using appendChild and has the same .....focus() code behind it as the first "google_win". But if this second one is clicked the google window is NOT focused on when IE is used. I've tried IE6 and 7 on XP and IE5.2 on OSX. This does work in Firefox and Safari.

This is the main window code:
[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Untitled</title>
</head>
<script type="text/javascript">
<!--
function opengoogle(){
address="http://www.google.com/"
google_win=window.open(address,'google_win')
}
function addtomenu(win_name){
sectRef = menuwin.document.getElementById('menu_list');
newLine = menuwin.document.createElement("br");
sectRef.appendChild(newLine);
newSpan = menuwin.document.createElement("span");
openscript = "window.opener." + win_name +".focus();"
newSpan.setAttribute('onClick',openscript);
newText = menuwin.document.createTextNode(win_name);
newSpan.appendChild(newText);
sectRef.appendChild(newSpan);
}
function openmenu(){
menuwin=window.open('menutest1.html','Menu','width =200,height=600,resizable=yes,scrollbars=auto,tool bar=yes,location=no,directories=no,status=yes,menu bar=yes,copyhistory=no,left=0,top=100,screenX=0,sc reenY=100');
}
//-->
</script>
<body>
<span onClick="openmenu()">Open Menu</span><br>
<span onClick="opengoogle()">Open Google</span><br>
<span onClick="addtomenu('google_win')">Add Google to Menu</span>
</body>
</html>[/HTML]

This code is for the menu window and belongs in a file called "menutest1.html"
[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Menu</title>
</head>
<body>
<div id='menu_list'>
<span onClick='window.opener.google_win.focus();'>google _win</span>
</div>
</body>
</html>[/HTML]

These pages are at: http://insitefo.com/domtest1.html

Any ideas how to get the added "google_win" line to work properly or why it's not working?

Thanks
Aug 30 '07 #1
4 2336
dmjpro
2,476 2GB
Fist of all you commented the Script Codes.
Anyway, the picture is not clear to me.
Actually what I understood that is if you click on Add Menu then the menu will be added there and the Menu_List window will be focused.
Right?
You want this?

Kind regards,
Dmjpro.
Aug 30 '07 #2
acoder
16,027 Expert Mod 8TB
On line 20,
Expand|Select|Wrap|Line Numbers
  1. newSpan.setAttribute("onclick",...);
will not work in IE. Try:
Expand|Select|Wrap|Line Numbers
  1. newSpan.onclick=...;
instead.
Aug 30 '07 #3
On line 20,
Expand|Select|Wrap|Line Numbers
  1. newSpan.setAttribute("onclick",...);
will not work in IE. Try:
Expand|Select|Wrap|Line Numbers
  1. newSpan.onclick=...;
instead.
I got that to work after a bit of work. I changed that setAttribute line to:
Expand|Select|Wrap|Line Numbers
  1. newSpan.onclick= function() {eval(win_name+".focus()");}
Thanks for the help.
Sep 11 '07 #4
acoder
16,027 Expert Mod 8TB
Glad to hear you got it working.

You don't need to use eval. You could use [] notation, e.g. replace
Expand|Select|Wrap|Line Numbers
  1. eval("window.opener." + win_name + ".focus();");
with
Expand|Select|Wrap|Line Numbers
  1. window.opener[win_name].focus();
Sep 11 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

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...
6
by: joe | last post by:
Hi Everyone, could anyone comment on the following problem: I have a textbox being appended to a cell in a table, and am trying to call focus() on like this: <snip> c01.removeChild(answerbox);...
5
by: mike | last post by:
I have a simple input element that is created dynamically using javascript as follows: myINPUT = document.createElement("INPUT"); myINPUT.type="text"; myINPUT.id = myINPUT.name = "amt"...
3
by: Praveen | last post by:
In IE a table element will receive focus when you either tab into it or when you click anywhere within the table. Mainly it fires the onfocus event. This doesn't happen in Mozilla (Firefox and...
3
by: mike | last post by:
I have a script that is not rendering the textwrap in svg properly. //does not work ..... var svgLand = svgObj.getElementById("NarrDisplay"); mytextwrap=...
4
by: bhatiaajay | last post by:
I am new to JavaScript objects. The object creates a button with no events attached. Later I want to attach an event to the button created by this object. The event attaches a function in the...
6
by: ApOG | last post by:
Hello everyone, I have this javascript code working perfectly with IE, but with firefox nothing happens when running the function... function add_div_field () { var ni =...
2
dlite922
by: dlite922 | last post by:
Before traversing my code, here's what my goal is and what this function does: I have a table of fields that dynamically grows as the user enters information. A minimum of 3 rows must always...
5
by: black143 | last post by:
Hi All, i am using this below addElement() function to create the file element dynamically function addElement( filename,businessName ){ // Make sure it's a file input element //if(...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.