PDA

View Full Version : screen.height and screen.width returning "undefined"..


ThreeRavens
02-09-2006, 03:13 PM
Iam trying to dynamicaly create some iframes based on the the screen res of the user's monitor...here is the code:


<script language="JavaScript">
var scr_width= screen.width;
var scr_height= screen.height;
var iframe_height = 0;
if(scr_height == 1280)
{iframe_height=1000;}
else if(scr_height==1024)
{iframe_height=1000;}
else{iframe_height=600;}
alert(iframe_height+'-'+scr_height+'x'+scr_width);
document.write('<iframe src="functions/reports/reports_circuit.cfm?fuseaction=reports" name="body_frame" width="100%" marginwidth="0" height="'+iframe_height+'" marginheight="0" align="top" scrolling="auto" frameborder="0" class="inside2CIframe2" allowtransparency="true"></iframe>');
</script>

the alert (put in for testing purposes) returns "600-undefinedxundefined" Why is it returning undefined?
HELP!!!!! *as I bang my head agaisnt the monitor* hehehe

Eric

Nischumacher
02-09-2006, 03:42 PM
try screen.availwidth and screen.availheight...

although what you have done seems fine...

ok...
your code works fine...
i am using IE6.

ThreeRavens
02-09-2006, 04:01 PM
Is there a reason why my code doesn't work? I am using IE 6 as well...it's the corp standard. Could it be a local server config issue based on company restrictions? This has me really boggled as it worked fine on the server that hosts my personal websites.

Eric

ThreeRavens
02-09-2006, 04:04 PM
try screen.availwidth and screen.availheight...

although what you have done seems fine...

ok...
your code works fine...
i am using IE6.
*************
I just made the suggested change and got the same results...grrr...

Eric

_Aerospace_Eng_
02-09-2006, 07:22 PM
Hmm try this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
<!--
var scr_width= screen.width;
var scr_height= screen.height;
var iframe_height = 0;
if(scr_height == 1280)
{
iframe_height=1000;
}
else if(scr_height==1024)
{
iframe_height=1000;
}
else{
iframe_height=600;
}
window.onload = function(){
document.getElementById('body_frame').height = iframe_height;
alert(iframe_height+'-'+scr_height+'x'+scr_width);
}
//-->
</script>
</head>

<body>
<iframe src="http://www.yahoo.com"" id="body_frame" name="body_frame" width="100%" height="600" marginwidth="0" scrolling="Auto" frameborder="0" class="inside2CIframe2" allowtransparency="true"></iframe>
</body>
</html>
I put the iframe directly into the body so just in case js is disabled the user wil still see the iframe. I'm not quite sure why your code didn't work as it worked for me.

felgall
02-09-2006, 10:06 PM
Who cares ow big the screen is, it is the space inside the browser window that is important.