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

window getElementByID works in IE but not in FireFox --- Help!

I am banging my head against the wall with this one. The following
code snippets work perfectly fine in MSIE6. But produce an error in
Firefox and do not work at all.

BROWSER.HTM
<HTML>
....
<div class="Abb">
<h2 id="ABTit">BROWSER</h2>
</div>
....
</HTML>

function MyFun() {
var aWin = window.open(strURL, 'BROWSERWIN',
"dependent=yes,menubar=no,resizable=yes,scrallbars =yes,toolbar=no,left=100,top=100,width=500,height= 400");

aWin.document.getElementById('ABTit').innerHTML='M YTEXT';
}

My INDEX.HTM file calls the MyFun function which opens the BROWSER.HTM
file. The MyFun function is trying to modify the BROWSER.HTM window
contents and style.

In FireFox this produces the following error in the JavaScript Console
"aWin.document.getElementById("ABTit") has no properties".

I've seen that one before and normally it means I made a spelling error
somewhere... But this time it works fine in MSIE 6 and not in Firefox.

aWin.document.writeln("TESTING") works fine in both browsers.

I've tried various combinations and various web sites. I'm stumped...

Help!

Jul 23 '05 #1
5 31195
Derek Erb wrote:
I am banging my head against the wall with this one. The following
code snippets work perfectly fine in MSIE6. But produce an error in
Firefox and do not work at all.

BROWSER.HTM
<HTML>
...
<div class="Abb">
<h2 id="ABTit">BROWSER</h2>
</div>
...
</HTML>

function MyFun() {
var aWin = window.open(strURL, 'BROWSERWIN',
"dependent=yes,menubar=no,resizable=yes,scrallbars =yes,toolbar=no,left=100,top=100,width=500,height= 400");

aWin.document.getElementById('ABTit').innerHTML='M YTEXT';
}

My INDEX.HTM file calls the MyFun function which opens the BROWSER.HTM
file. The MyFun function is trying to modify the BROWSER.HTM window
contents and style.

In FireFox this produces the following error in the JavaScript Console
"aWin.document.getElementById("ABTit") has no properties".

I've seen that one before and normally it means I made a spelling error
somewhere... But this time it works fine in MSIE 6 and not in Firefox.

aWin.document.writeln("TESTING") works fine in both browsers.

I've tried various combinations and various web sites. I'm stumped...


The most likely reason is that ABTit does not exist when
document.getElementById() tries to get it - the new window is still
creating the document.

--
Fred
Jul 23 '05 #2
Derek Erb wrote:
I am banging my head against the wall with this one. The following
code snippets work perfectly fine in MSIE6. But produce an error in
Firefox and do not work at all.

BROWSER.HTM
<HTML>
...
<div class="Abb">
<h2 id="ABTit">BROWSER</h2>
</div>
...
</HTML>

function MyFun() {
var aWin = window.open(strURL, 'BROWSERWIN',
"dependent=yes,menubar=no,resizable=yes,scrallbars =yes,toolbar=no,left=100,top=100,width=500,height= 400");
aWin.document.getElementById('ABTit').innerHTML='M YTEXT';
}

My INDEX.HTM file calls the MyFun function which opens the BROWSER.HTM file. The MyFun function is trying to modify the BROWSER.HTM window
contents and style.

In FireFox this produces the following error in the JavaScript Console "aWin.document.getElementById("ABTit") has no properties".

I've seen that one before and normally it means I made a spelling error somewhere... But this time it works fine in MSIE 6 and not in Firefox.
aWin.document.writeln("TESTING") works fine in both browsers.

I've tried various combinations and various web sites. I'm stumped...
Help!


All window.open() does is 1) open a new window, 2) set its location to
the specified url, and 3) return the new window object. The last -
which allows any subsequent code to run - is not necessarily
synchronous with the new document loading and being available for
scripting. One way to avoid this is to load the new document as a
javascript: url (favelet): as this is loaded into window.location, like
a file, it always works. Depends on how elaborate the document is, and
whether there needs to be any preprocessing of it back at the server.
Here's a sample:

Put something like this in the opener window:

function getDoc(myText)
{
return [

'<html><head><title>Yo!</title></head>' ,
'<body style="background:.........' ,
'<div class="Abb"><h2 id="ABTit">' ,
myText ,
'</h2></div>........etc..........'

].join('');
}

Then:

var aWin = null;
function MyFun(myText)
{
aWin = window.open(
'javascript:opener.getDoc("' + myText + '")',
'BROWSERWIN',

'menubar=no,resizable=yes,scrollbars=yes,toolbar=n o,left=100,top=100,width=500,height=400'
);
}

..........

MyFun('MYTEXT');

Jul 23 '05 #3
Thank you for your reply.

I don't understand why the window would be open in MSIE but still be
creating the document in Firefox.

However, regardless, is there some way to make my code wait until the
window is created and the document is ready so that I am certain I can
modify it?

Thank you in advance for your assistance.

Jul 23 '05 #4
Derek Erb wrote:
Thank you for your reply.

I don't understand why the window would be open in MSIE but still be
creating the document in Firefox.
Because once the script has created the window, it has finished its
job and moves on. The window then proceeds to load the document at
its own pace.

As for why one browser has finished creating the document and the
other hasn't - browser inconsistency is one of the fundamental
attractions of web programming.

However, regardless, is there some way to make my code wait until the
window is created and the document is ready so that I am certain I can
modify it?


Read RobB's post below.

--
Fred
Jul 23 '05 #5
DU
Derek Erb wrote:
I am banging my head against the wall with this one. The following
code snippets work perfectly fine in MSIE6. But produce an error in
Firefox and do not work at all.

BROWSER.HTM
<HTML>
...
<div class="Abb">
<h2 id="ABTit">BROWSER</h2>
</div>
...
</HTML>

function MyFun() {
var aWin = window.open(strURL, 'BROWSERWIN',
"dependent=yes,menubar=no,resizable=yes,scrallbars =yes,toolbar=no,left=100,top=100,width=500,height= 400");
var aWin:
Creating a local reference to the window object is not recommendable. As
soon as you're outside the scope of the function, that reference is
useless. The only way you can overcome the asynchronous problem of
window creating and document loaded and functional is to use a global
variable to store the window reference and then use it from the opener
to modify your node.

dependent=yes: will not work in MSIE 6
scrallbars=yes: will not render scrollbars if needed, if content
overflows window dimensions in all browsers

aWin.document.getElementById('ABTit').innerHTML='M YTEXT';


Poor usage of innerHTML: you have no node to insert, just a text node.
It's much better to use DOM 2 CharacterData attribute or just setting
the nodeValue directly. It's not only using web standards, it's not only
supported by MSIE 5+, Mozilla-based browsers, Safari 1.x, Opera 7.x,
Konqueror 3.x,etc. but it is also more efficient than innerHTML and it
is not a W3C DOM attribute.

DU
--
The site said to use Internet Explorer 5 or better... so I switched to
Mozilla 1.7.7 :)
Jul 23 '05 #6

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

Similar topics

4
by: LargePig | last post by:
I have some code that works in IE: function simple_example() { myarray = "element1of12" thiselement = document.getElementById(myarray) } But it does not work in firefox, returns 'null'.
13
by: tochiromifune | last post by:
Hello The window.open method brings my window to the top only if it is new. If it's being reused, the window does not come to the foreground (with IE 6 it does). Is there a new way in...
4
by: the other john | last post by:
I came across a third party script I want to learn how to configure as well as learn more dhtml in the doing. I'm not much of a JS guy yet but I'm working on it. This script works fine in IE6...
1
by: Curious Trigger | last post by:
Hi there, programming with Visual Studio 2005 and ASP.NET 2.0 I want to open a modal dialog from Default.aspx. I searched the net and many newsgroups but I couldn't find any solution. First I...
2
by: yb | last post by:
I am attempting to modify the style of an element (its width) as the window is being resized, in firefox. Long story short, I've tried to use CSS but one particular part of the layout just won't...
13
by: amymcdo3 | last post by:
Hi Everyone, I have a popup window that opens when clicking a link. The pop up window asks a question and supplies two buttons, Yes and No. The buttons are images and when the user clicks the...
21
rrocket
by: rrocket | last post by:
This works great in IE, but does not do anything in FireFox... Any ideas of what could be wrong with it? I checked all of the values (in IE through alert statements since nothing shows up in...
5
by: dmk | last post by:
Hi All, function getWindowSize() { var myWidth = 0, myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myWidth = window.innerWidth; myHeight =...
9
by: ninhovid | last post by:
Hi... i'm new at dhtml, and i want to use it in help windows (instead of window.open() of javascript)... i'm done it... but it works only in internet explorer.. in firefox 2 and 3 it opens the...
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
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.