473,840 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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">BROW SER</h2>
</div>
....
</HTML>

function MyFun() {
var aWin = window.open(str URL, 'BROWSERWIN',
"dependent=yes, menubar=no,resi zable=yes,scral lbars=yes,toolb ar=no,left=100, top=100,width=5 00,height=400") ;

aWin.document.g etElementById(' ABTit').innerHT ML='MYTEXT';
}

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.w riteln("TESTING ") works fine in both browsers.

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

Help!

Jul 23 '05 #1
5 31229
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">BROW SER</h2>
</div>
...
</HTML>

function MyFun() {
var aWin = window.open(str URL, 'BROWSERWIN',
"dependent=yes, menubar=no,resi zable=yes,scral lbars=yes,toolb ar=no,left=100, top=100,width=5 00,height=400") ;

aWin.document.g etElementById(' ABTit').innerHT ML='MYTEXT';
}

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.w riteln("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.getEle mentById() 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">BROW SER</h2>
</div>
...
</HTML>

function MyFun() {
var aWin = window.open(str URL, 'BROWSERWIN',
"dependent=yes, menubar=no,resi zable=yes,scral lbars=yes,toolb ar=no,left=100, top=100,width=5 00,height=400") ;
aWin.document.g etElementById(' ABTit').innerHT ML='MYTEXT';
}

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.w riteln("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><t itle>Yo!</title></head>' ,
'<body style="backgrou nd:.........' ,
'<div class="Abb"><h2 id="ABTit">' ,
myText ,
'</h2></div>........etc ..........'

].join('');
}

Then:

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

'menubar=no,res izable=yes,scro llbars=yes,tool bar=no,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">BROW SER</h2>
</div>
...
</HTML>

function MyFun() {
var aWin = window.open(str URL, 'BROWSERWIN',
"dependent=yes, menubar=no,resi zable=yes,scral lbars=yes,toolb ar=no,left=100, top=100,width=5 00,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.g etElementById(' ABTit').innerHT ML='MYTEXT';


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
19706
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
22183
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 Mozilla/Firefox that I can ensure that this window comes to the top? Thank you for your help
4
2674
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 but is a dead fish in FireFox. There is no support offered on the site where it came from. I'd really appreciate help with this as it will not only to get it working but to learn how it all works so I can add it to my repertoire. Thanks!
1
7670
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 tried using two aspx pages with standard controls and all those post-backs and their attributes OnClientClick. Since this didn't work, i reduced it to a default.aspx page opening a pure html-page as a modal dialog.
2
5216
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 do what I need. The javascript solution assigns a function to window.onresize that sets the inline style, it works with one problem -- the handler only gets called after the resizing stops, and so there is noticeable lag before it redraws.
13
3252
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 button, they will either be linked to another page via the Yes button or they will stay on the same page if they click the No button. The popup window is supposed to close once the Yes or No button is clicked, and it does, however, it ignores the...
21
2717
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 FireFox) and everything is valid. Thanks... function spanHide(spanNum){ for(startValue = 1;startValue <= 8;startValue++){ var currentSpan = eval("document.all.spanShip"+spanNum+"_"+startValue); var InsureInfo_SpanInsure =...
5
7498
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 = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
9
5325
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 dhtml modal window but in the background of my main page... what do i have to correct so it opens up in front as it does in internet explorer? i'm using c# and ajax... it's an asp.net app... in masterpage i have this: <link rel="stylesheet"...
0
9699
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10921
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10601
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10300
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9437
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5685
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4498
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
2
4072
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.