473,379 Members | 1,187 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,379 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 2340
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(...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.