Help with this javascript

Chris S

Retired
Messages
2,055
Reaction score
1
Points
38
I need some javascript code that works in both IE, Firefox. I need it to detect the screen resolution. and if the resolution is greater then 800x600 use the code below

Code:
#main {
	text-align: left;
	margin: 10px auto;
	width: 700px;
	background: #fff;
	padding: 20px 30px 70px;
	border-top: 1px solid #E6E6DF;
	border-right: 1px solid #E6E6DF;
	border-bottom: 5px solid #E6E6DF;
	border-left: 1px solid #E6E6DF;
	}
 

Trixter

New Member
Messages
384
Reaction score
0
Points
0
The command your looking for is screen.width & screen.height.

Code:
<SCRIPT language="JavaScript">
<!--
if ((screen.width>=800) && (screen.height>=600))
{
#main {
	text-align: left;
	margin: 10px auto;
	width: 700px;
	background: #fff;
	padding: 20px 30px 70px;
	border-top: 1px solid #E6E6DF;
	border-right: 1px solid #E6E6DF;
	border-bottom: 5px solid #E6E6DF;
	border-left: 1px solid #E6E6DF;
	}
}
//-->
</SCRIPT>
Should Do The Trick
 
Last edited:

Cubeform

New Member
Messages
339
Reaction score
0
Points
0
Trixter said:
The command your looking for is screen.width & screen.height.

Code:
//There was some code here before, but I removed it from the quote. Check the post above.
Should Do The Trick

Won't work. Chris S posted CSS. This will, though:

HTML:
<script type="text/javascript">
<!--
var temp = document.getElementById('main');
if ((screen.width>=800) && (screen.height>=600))
  {
    temp.style.text-align= "left";
    temp.style.margin="10px auto";
    temp.style.width="700px";
    temp.style.background="#fff";
    temp.style.padding="20px 30px 70px";
    temp.style.border-top="1px solid #E6E6DF";
    temp.style.border-right="1px solid #E6E6DF";
    temp.style.border-bottom="5px solid #E6E6DF";
    temp.style.border-left="1px solid #E6E6DF";
  }
  else 
  {
  //apply your other style
  }
//-->
</script>

Replace "temp" with any variable name you like. Note that I added ".style." and converted the colons into "=". I'm sure there's another way to do it that's easier and better, because I'm not a JavaScript (or HTML DOM) expert.
 
Last edited:
Top