dmk 5
New Member
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'
-
myWidth = document.documentElement.clientWidth;
-
myHeight = document.documentElement.clientHeight;
-
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
-
//IE 4 compatible
-
myWidth = document.body.clientWidth;
-
myHeight = document.body.clientHeight;
-
}
-
window.alert( 'Width = ' + myWidth );
-
window.alert( 'Height = ' + myHeight );
-
-
//call resize
-
resizeContent(myHeight, myWidth)
-
}
-
-
function resizeContent(windowHeight, windowWidth){
-
document.getElementById('content').style.height = windowHeight-107;
-
window.alert(document.getElementById('content').style.height);
-
}
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
5 7495
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'
-
myWidth = document.documentElement.clientWidth;
-
myHeight = document.documentElement.clientHeight;
-
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
-
//IE 4 compatible
-
myWidth = document.body.clientWidth;
-
myHeight = document.body.clientHeight;
-
}
-
window.alert( 'Width = ' + myWidth );
-
window.alert( 'Height = ' + myHeight );
-
-
//call resize
-
resizeContent(myHeight, myWidth)
-
}
-
-
function resizeContent(windowHeight, windowWidth){
-
document.getElementById('content').style.height = windowHeight-107;
-
window.alert(document.getElementById('content').style.height);
-
}
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 .... -
alert(windowHeight+"\t"+windowWidth);
-
Best of Luck.
Kind regards,
Dmjpro.
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 .... -
alert(windowHeight+"\t"+windowWidth);
-
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 - 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.
Yes, this does work, however it is not what is wrong, you may notice that in the resizeContent function I have the following line - 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.
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 - 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: - function resizeContent(windowHeight, windowWidth){
-
pageElement = document.getElementById("content");
-
calcHeight = windowHeight - 113;
-
pageElement.style.height = calcHeight + "px";
-
}
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. 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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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;
|
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...
|
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":
|
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:
|
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>
| |
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...
|
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
|
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:...
|
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...
|
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,...
|
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...
| |
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| | |