PDA

View Full Version : Improved 'Screen resolution detection and notification Script'



charityalbumman
03-04-2010, 07:26 AM
1) CODE TITLE: Screen resolution detection and notification Script (this script (http://dynamicdrive.com/dynamicindex9/info1.htm))

2) AUTHOR NAME/NOTES: Peter Slater (edited) / Dynamic Drive (original)

3) DESCRIPTION:

This is an updated script that Dynamic drive put up. It is a simple script which checks your viewers screen resolution against a set resolution (default set as 800 by 600). All you need to do is paste the code into your BODY section and the code will display lines as seen above on your web page. Feel free to change the script so it provides an alert instead (but make sure you change the <br> html to \n for the new lines to work). It is also possible to name the script as a function and use the Body Onload feature to call the function (which means you would need to store the JavaScript in the head section or in an external file).

4) URL TO CODE:

or, ATTACHED BELOW (see #3 in guidelines below):

Preview Here (http://peterslater.webs.com/Script_TEST.html)

Includes a very simple if else statement to check to see if the screen resolution is set to what the web site is best viewed at.

Output as a displayed text via a ‘document.write’ statement, however can be changed to an alert message J

Also if you want you can also name it as a function (suppose call it check_res()) and then call that using the onload within the body tag.

Paste the following code where you wish the text to appear on your web page:



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

/*
Screen resolution detection and notification Script-
© Peter Slater (original source by DynamicDrive)
I edited it to fix an issue with their script
If using 'alert' instead of 'document.write', remember to change the '<br>' to '\n' for the new line
Feel free to name the script as a function and call it using the body onload feature
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 web site is bested viewed with a screen resolution of "+correctwidth+"*"+correctheight+".<br>Your current resolution is "+screen.width+"*"+screen.height+".<br>You do not need to change your settings.");
else
document.write("This web site is bested viewed with a screen resolution of "+correctwidth+"*"+correctheight+".<br>Your current resolution is "+screen.width+"*"+screen.height+".<br>It is recommended you change your screen resolution to "+correctwidth+"*"+correctheight+".");
//-->
</script>