473,796 Members | 2,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

document.getEle mentById works in IE as expected, but not in Firefox

5 New Member
Hi All,

Expand|Select|Wrap|Line Numbers
  1. function getWindowSize() {
  2.   var myWidth = 0, myHeight = 0;
  3.   if( typeof( window.innerWidth ) == 'number' ) {
  4.     //Non-IE
  5.     myWidth = window.innerWidth;
  6.     myHeight = window.innerHeight;
  7.   } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  8.     //IE 6+ in 'standards compliant mode'
  9.     myWidth = document.documentElement.clientWidth;
  10.     myHeight = document.documentElement.clientHeight;
  11.   } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  12.     //IE 4 compatible
  13.     myWidth = document.body.clientWidth;
  14.     myHeight = document.body.clientHeight;
  15.   }
  16.   window.alert( 'Width = ' + myWidth );
  17.   window.alert( 'Height = ' + myHeight );
  18.  
  19.   //call resize
  20.     resizeContent(myHeight, myWidth)
  21. }
  22.  
  23. function resizeContent(windowHeight, windowWidth){
  24.     document.getElementById('content').style.height = windowHeight-107;
  25.     window.alert(document.getElementById('content').style.height);
  26. }
The function getWindowSize() is run at "onload" and "onresize" on the body tag.

It works as expected on Internet Explorer 7, however I also need it to work on Firefox. Basically the getWindowSize() function gets the innerWidth and innerHeight of the window and then calls the resizeContent function which resizes the DIV with the ID "content". this is required as the page is for an assignment and I need to rewrite an original frames page (i know, i know, why?????) and i want to make it exactly the same.

The window.alert in the resizeContent function shows that "document.getEl ementById('cont ent').style.hei ght" returns null for firefox and the correct value for IE.

Any help would be appreciated.

Cheers
Sep 4 '07 #1
5 7496
dmjpro
2,476 Top Contributor
Hi All,

Expand|Select|Wrap|Line Numbers
  1. function getWindowSize() {
  2.   var myWidth = 0, myHeight = 0;
  3.   if( typeof( window.innerWidth ) == 'number' ) {
  4.     //Non-IE
  5.     myWidth = window.innerWidth;
  6.     myHeight = window.innerHeight;
  7.   } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  8.     //IE 6+ in 'standards compliant mode'
  9.     myWidth = document.documentElement.clientWidth;
  10.     myHeight = document.documentElement.clientHeight;
  11.   } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  12.     //IE 4 compatible
  13.     myWidth = document.body.clientWidth;
  14.     myHeight = document.body.clientHeight;
  15.   }
  16.   window.alert( 'Width = ' + myWidth );
  17.   window.alert( 'Height = ' + myHeight );
  18.  
  19.   //call resize
  20.     resizeContent(myHeight, myWidth)
  21. }
  22.  
  23. function resizeContent(windowHeight, windowWidth){
  24.     document.getElementById('content').style.height = windowHeight-107;
  25.     window.alert(document.getElementById('content').style.height);
  26. }
The function getWindowSize() is run at "onload" and "onresize" on the body tag.

It works as expected on Internet Explorer 7, however I also need it to work on Firefox. Basically the getWindowSize() function gets the innerWidth and innerHeight of the window and then calls the resizeContent function which resizes the DIV with the ID "content". this is required as the page is for an assignment and I need to rewrite an original frames page (i know, i know, why?????) and i want to make it exactly the same.

The window.alert in the resizeContent function shows that "document.getEl ementById('cont ent').style.hei ght" returns null for firefox and the correct value for IE.

Any help would be appreciated.

Cheers

Welcome to TSDN!
Please one thing Do.
Test the value of windowHeight or windowWidth passed as parameters to resizeContent function, using ....
Expand|Select|Wrap|Line Numbers
  1. alert(windowHeight+"\t"+windowWidth);
  2.  
Best of Luck.

Kind regards,
Dmjpro.
Sep 4 '07 #2
dmk
5 New Member
Welcome to TSDN!
Please one thing Do.
Test the value of windowHeight or windowWidth passed as parameters to resizeContent function, using ....
Expand|Select|Wrap|Line Numbers
  1. alert(windowHeight+"\t"+windowWidth);
  2.  
Best of Luck.

Kind regards,
Dmjpro.
Yes, this does work, however it is not what is wrong, you may notice that in the resizeContent function I have the following line

Expand|Select|Wrap|Line Numbers
  1. window.alert(document.getElementById('content').style.height);
This is returning null in Firefox and the correct value in IE... this is where the problem is occuring.
Sep 4 '07 #3
dmjpro
2,476 Top Contributor
Yes, this does work, however it is not what is wrong, you may notice that in the resizeContent function I have the following line

Expand|Select|Wrap|Line Numbers
  1. window.alert(document.getElementById('content').style.height);
This is returning null in Firefox and the correct value in IE... this is where the problem is occuring.
Actually that's why i told you to check before set the value of Height.
Now without set the height you check your own alert, and see what it returns.
If windowHeight and windowWidth returns numeric digit then it would be no problem.
If the windowHeight is String then try to covert it using parseInt.

Kind regards,
Dmjpro.
Sep 4 '07 #4
dmk
5 New Member
Yes, this does work, however it is not what is wrong, you may notice that in the resizeContent function I have the following line

Expand|Select|Wrap|Line Numbers
  1. window.alert(document.getElementById('content').style.height);
This is returning null in Firefox and the correct value in IE... this is where the problem is occuring.
This issue was solved because firefox does not automatically add "px" to the end of the value entered while IE does.

The code was changed to the following:

Expand|Select|Wrap|Line Numbers
  1. function resizeContent(windowHeight, windowWidth){
  2.     pageElement = document.getElementById("content");
  3.     calcHeight = windowHeight - 113;
  4.     pageElement.style.height =  calcHeight + "px";
  5. }
Note that you do not need to write it out on two lines (i.e. you can use document.getEle mentById("conte nt").style.heig ht if you want to.
Sep 4 '07 #5
gits
5,390 Recognized Expert Moderator Expert
hi ...

yep ... this is due to the correct behaviour of firefox here ... the units has to be applied by the programmer ... and IE guesses that you wanted 'px'. So the best way - and i would always recommend that - is to develop with FF/MOZ and then test it in other browsers too ...

initial development with IE mostly gets you to adapt the entire code for standards-compliant browsers (you find a lot of this problems here in the forum too) in case you use IE-specifics in your code ... but using the standards methods that the other browsers support ... will mostly work in IE too ... and you have much less adaptions to do ...

conclusion: develop to the standards and test with standards-compliant browsers such as firefox ... after that ... get it to work with IE and other browsers too ... that will save you a lot of time ... i promise ;)

kind regards
Sep 4 '07 #6

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

Similar topics

8
1833
by: bradwiseathome | last post by:
I have code that works in IE 6 but does not work in FireFox 1.0.2, how can I change it so it works in both browsers? <html> <head> <script language="JavaScript" type="text/JavaScript"> function AttributeSelected() { var selectVal = document.forms.elements.options;
7
2409
by: Andrea | last post by:
Hi there - I'm hoping someone can help me; I've been struggling with this for a few days! :-) I have a webpage that is comprised of many forms containing questions. As the user answers one of the questions, that form is hidden and the next is displayed. Also, as the user answers each question a "count" variable is updated based on their response. I would like the question to show up on the left side and the answer to show up in the...
2
2240
by: Phlip | last post by:
JavaScripters: Steps to reproduce the bug: Save this in "outer.html": <div id='updateMe'></div> <iframe src='inner.html'/> Now save this into "inner.html":
13
4967
by: RommelTJ | last post by:
Hi, My website (http://www.justiceinmexico.org/indextest.php) looks good in Firefox, but horrible in IE, and I think it's because of an error in the javascript of a free web ticker I got off the internet. When I run Firebug on it, it says: document.getElementById("TICKER") has no properties TICKER_CONTENT = document.getElementById("TICKER").innerHTML; Here is the complete script:
4
1484
by: smartic | last post by:
Hi everyone. I'm having problem with firefox only but it works when i delete document definition that is my code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head>
2
13907
by: jmatos | last post by:
I need to change the style of an element changing its padding-left property (got it in firefox but IE is a different battle..). I can use document.getElementById().style.XX to everything i need, except with padding-left, as it is separated by a ' - ' and it is not correct to use it as it was supposed to: document.getElementById('el').style.padding-left = '5px' will throw 'invalid assignment left-hand side', as expected.. Any help...
29
19292
by: Nick | last post by:
I've seen a few frameworks use the following: function $(id) { return document.getElementById(id); } Then to use: $('something').innerHTML = 'blah'; I'm just trying to roll this out to my site and so far doing this has saved about 8KB of javascript (lots of ajax/dynamic elements). I just
2
3922
by: vegetable21 | last post by:
Hi, I'm relatively new to JavaScript, but not to programming. I'm trying to get a table to expand and collapse within a cell of my master table. However i want to collapse all the other open tables when i expand a new one. I'm nearly there but i get an error that i can't seem to shake. Firefox show me the error as the following: Error: document.getElementById("more" + i) is null Source File:...
0
9685
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9533
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
10239
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...
1
10190
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7555
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4122
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
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.