Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting Resolution

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
Is it possible to either detect a user's screen resolution (and make a popup depending on which it is) or to detect when the cursor has "bumped" the limits of the browser window? If the second idea can be done, I would need a popup or alert that would appear only the first time that happened. Can one of these be done - and how?
 
<script language=javascript>
<!--
function showRes(){

alert(&quot;Screen width: &quot; + screen.width + &quot; height: &quot; + screen.height);
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<input type=&quot;button&quot; value=&quot;Show Resolution&quot; onclick=&quot;showRes()&quot;>

Good luck
-pete
 
Thanks palbano!

With your code, I have it working via clicking on an image that was already there rather than a form button (and it seems to work fine), but I want it be automatic. I already have an onLoad in my body tag. Can there be two, like this? If so, then I apparently don't have the onLoad function called preperly.

[tt]onLoad=&quot;this.document.keyword.Keywords.focus();&quot; onLoad=&quot;showRes();&quot;[/tt]

Since I'm already loading other JavaScript from a separate file, I added a modified version of your code to it for testing purposes:

[tt] function showRes(){
if (screen.width < 800 || screen.height < 600){
alert(&quot;Your Screen settings are:\nWidth: &quot; + screen.width + &quot; \nHeight: &quot; + screen.height + &quot;\nColor Depth: &quot; + screen.depth + &quot;\n\nThe minimum recommended setting\nfor viewing this site is 800 X 600&quot;);
return false;
}
}[/tt]

I know the color.depth is not right (what is the proper syntax?) but just need to make the rest of it automatic now.

Don
 
OK, The resolution detector alert is now working automatically with the above code, though apparently two onLoad() can't be used together. Since it's a frames site, I called one from the menu and the other from the main document. I consider this a &quot;work-around&quot; unless someone knows that they cannot be called together. Is there a better way to do it?

Don
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top