PDA

View Full Version : quick hand needed to modify a screen solution detector script



canadianjameson
Sep 12th, 2007, 06:18 PM
Hi all,

I'm trying to convert this script:


<script language="JavaScript1.2">
<!--

/*
Screen resolution detection and notification Script-
Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions,
100's more DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
*/

var correctwidth=800
var correctheight=600
if (screen.width!=correctwidth||screen.height!=correctheight)
document.write("This webpage is bested viewed with screen resolution "+correctwidth+"*"+correctheight+". Your current resolution is "+screen.width+"*"+screen.height+". If possible, please change the resolution!")
//-->
</script>


to do as follows:
If the user's screen resolution is less than 1024x768, set the <span id="resolution"> to display: block



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Welcome to Head & Hands</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="css/main.css" type="text/css">



<style type="text/css">
#resolution {
display: none
}
</style>

</head>

<body>
<script language="JavaScript1.2">
<!--

/*
Screen resolution detection and notification Script-
Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions,
100's more DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
*/

var correctwidth=1024
var correctheight=768
if (screen.width<correctwidth||screen.height<correctheight) {
document.getElementById('resolution').style.display = 'block';
}
//-->
</script>
<span id="mainLogo"><img src="images/logo_700px.gif"></span>
<span id="english"></span> <span id="french"></span>

<span id="resolution">This webpage is bested viewed with a screen resolution of 1024x768 or higher.</span>
</body>
</html>

Any idea why this isn't working?

Also if there is a better way to do this please let me know

mic2100
Sep 12th, 2007, 07:00 PM
Yeah the javascript need to be in a function like this...



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Welcome to Head & Hands</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="css/main.css" type="text/css">



<style type="text/css">
#resolution {
visibility:hidden;
}
</style>

</head>

<body onLoad="init();">
<script language="JavaScript1.2">
<!--

/*
Screen resolution detection and notification Script-
Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions,
100's more DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
*/

function init()
{

var correctwidth=1024
var correctheight=768
if (screen.width<correctwidth||screen.height<correctheight) {
alert('block view');
document.getElementById('resolution').style.visibility = 'visible';
document.getElementById('resolution').style.display = 'block';
}

}
//-->
</script>
<span id="mainLogo"><img src="images/logo_700px.gif"></span>
<span id="english"></span> <span id="french"></span>

<span id="resolution">This webpage is bested viewed with a screen resolution of 1024x768 or higher.</span>
</body>
</html>


i have test this in IE7 and it works fine & displays the text in the resolution is un the specified amount.

canadianjameson
Sep 12th, 2007, 07:24 PM
perfect, thanks :)