PDA

View Full Version : Help With Screen Resolution Detection



rickjwilliams
12-28-2005, 07:22 PM
Hello,

I would like to use the java script code below on my splash screen for screen resolution detection.

But what I would like for it to do is give an "alert notice". Like the one used in
the code for "NO right mouse button". Could someone tell me , or show me how this is done?

Thanks, :)

Rick



<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.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>

jscheuer1
12-28-2005, 09:34 PM
When simply providing information, the document.write() method can always be replaced by the alert() method, though not always the other way around. So, assuming this is a valid DD script that works as written (looks to be), you can just switch from document.write to alert:


<script type="text/javascript">

/*
Screen resolution detection and notification Script-
&#169; 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)
alert("This webpage is best viewed with screen resolution "+correctwidth+"*"+correctheight+". Your current resolution is "+screen.width+"*"+screen.height+". If possible, please change the resolution!")

</script>

Notes: Extraneous 'hiding comments' removed. Opening script tag updated to current convention.

12345c
12-28-2005, 10:42 PM
Or

<script>
onload=function(){if (screen.width!=correctwidth||screen.height!=correctheight)
document.getElementById('alert1').innerHTML=
("This webpage is best viewed with screen resolution "+correctwidth+"*"+correctheight+". Your current resolution is "+screen.width+"*"+screen.height+". If possible, please change the resolution!");}
</script>
<body>
<div id=alert1></div> ...

rickjwilliams
12-28-2005, 10:42 PM
How simple, Thank you!

Rick