View Full Version : Screen resolution and detection script edit - valid?

01-11-2007, 03:55 AM
1) Script Title:
Screen resolution and detection script
2) Script URL (on DD):
3) Describe problem:
I'd just like to quickly ask if this is valid, and if it isn't, a version that would work:

<script language="JavaScript1.2">

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=640
var correctheight=480
if (screen.width<=correctwidth||screen.height<=correctheight)
document.write("<table border='1' width='100&#37;' align='center'>")
document.write("<table border='1' width='75%' align='center'>")

The result should be that if the screen resolution of a person is less or equal to 640x480 a start table tag should be written with a size 100%, if it isn't (eg 1024x768) then draw it 75%

01-11-2007, 10:57 AM
I don't think you meant valid. It isn't and neither was the script that you adapted it from. Validation has to do with following standards for HTML code in your hard coded HTML, here this is in the script tag. Both scripts use the language attribute. This has been deprecated in favor of the type attribute which is now required:

<script type="text/javascript">

You can make this change in full confidence.

Now, what I think you meant is, will it work. It looks like it will. I'm not so sure it is a great idea though. Screen resolution does not necessarily have anything to do with the size of the browser window. Also, your markup should be able to adapt to different sized windows without resorting to javascript, unavailable or disabled in many browsers. Without javascript, in this case you would have no table.