Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Getting Screen Resolution using Javascript.
OpaQue
post Sep 1 2004, 11:14 AM
Post #1


Administrator
Group Icon

Group: Admin
Posts: 458
Joined: 26-August 04
Member No.: 1



Is it possible to get the screen resolution of the users moniter using only javascript. No other external stuff, just pure javascript. I guess most of the people using JAVA for this. I also got some scripts regarding this which used SCREEN.WIDTH function or something, but they did not seem to work out. Any possible solutions.
BTW, is it possible to get the resolution using PHP ( I guess it is not ) ...
Go to the top of the page
 
+Quote Post
Cloak
post Sep 1 2004, 03:18 PM
Post #2





Guests






It is possible with JavaScript, because it is client-side - but not with PHP, as it is server-side.
Go to the top of the page
 
+Quote Post
mastercomputers
post Sep 1 2004, 11:39 PM
Post #3


BUG.SWAT.PATROL
Group Icon

Group: Members
Posts: 622
Joined: 1-September 04
From: Auckland, New Zealand
Member No.: 27



QUOTE(OpaQue @ Sep 2 2004, 12:14 AM)
Is it possible to get the screen resolution of the users moniter using only javascript. No other external stuff, just pure javascript. I guess most of the people using JAVA for this. I also got some scripts regarding this which used SCREEN.WIDTH function or something, but they did not seem to work out. Any possible solutions.
BTW, is it possible to get the resolution using PHP ( I guess it is not ) ...
*



This is quite easy, but when you say screen.width doesn't seem to work makes me wonder what the problem could be?

screen.width and screen.height work with NS 4+ and IE 5+ web browsers.

We can output on our site what their resolution our viewers are running at, dependant on their browser.

to do this we do:

CODE

<script language="javascript">
<!--
document.write('<p> +screen.width+ ' x ' +screen.height+ '</p>');
//-->
</script>


You can't use PHP to grab client information because it is a server-side script and has no involvement with the client. If you're wondering how you get browser agent names and such, that is because this is sent within the HTTP Headers upon request.

Usually you would use a mix of JavaScript and PHP to help you with creating optimised sites for your viewers.


Cheers, MC
Go to the top of the page
 
+Quote Post
wizzywig
post Sep 6 2004, 05:54 AM
Post #4


Member [ Level 1 ]
Group Icon

Group: [HOSTED]
Posts: 39
Joined: 6-September 04
From: England
Member No.: 294



ok thanks useful
Go to the top of the page
 
+Quote Post
Kiwi
post Sep 10 2004, 02:21 PM
Post #5


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 3
Joined: 9-September 04
From: Norway
Member No.: 426



QUOTE(OpaQue @ Sep 1 2004, 01:14 PM)
BTW, is it possible to get the resolution using PHP ( I guess it is not ) ...

With the combination of server side scripting and client side scripting, it is possible:
CODE
<script language="javascript">
<!--
 document.write('<a href=getscrsize.php?scrw='+screen.width+'&scrh='+screen.height+'>');
//-->
</script>
Clich here to tell what me your screen size is!</a>

Then, in the PHP script, you can get the screen size by using these two variables:
CODE
$_GET['scrw']
$_GET['scrh']
Go to the top of the page
 
+Quote Post
OrbitPoints
post Sep 13 2004, 02:02 AM
Post #6


Member [ Level 1 ]
Group Icon

Group: [HOSTED]
Posts: 31
Joined: 9-September 04
Member No.: 402



Some browsers (I think ns4 and below) use 'screen.availWidth' to get width and screen.availHeight to get height.

Try that if screen.width and screen.height does not work.
Go to the top of the page
 
+Quote Post
Feedbacker
post Jan 29 2008, 07:46 AM
Post #7


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 0
Joined: 1-November 07
Member No.: 25,869



Getting Screen Resolution using Javascript.
Getting Screen Resolution using Javascript.

<A HREF="javascript:alert('Your resolution is '+screen.Width+'x'+screen.Height);">
Click for your screen resolution</A>


-Sathish kumar
Go to the top of the page
 
+Quote Post
Jared
post May 8 2008, 03:36 AM
Post #8


Member [ Level 1 ]
Group Icon

Group: [HOSTED]
Posts: 40
Joined: 17-April 08
Member No.: 29,853



I am curious... Is there a way to get the height and width of the viewing area as opposed to the entire screen? Let's say for example that I have a website that will direct users to different HTML pages depending on their resolution. But it still will not display properly if a user uses only half a screen for their browser.

I would just like to get the width from the inside of the border on the left to the scroll bars on the right and the height from the bottom of the toolbars to the top of the status bar. Can this be done?

- Jared
Go to the top of the page
 
+Quote Post
toby
post May 8 2008, 08:45 AM
Post #9


Premium Member
Group Icon

Group: Members
Posts: 422
Joined: 29-September 06
Member No.: 16,228



No, there's no way to know if a browser window is maximised or anything like that.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. How To Create A Popup Window With Javascript?(19)
  2. javascript vs java(12)
  3. Javascript: Disable Mouse Right-click In Browser(16)
  4. Best Way To Learn Javascript(9)
  5. Javascript: Text To Texbox And Back To Text(2)
  6. Unobtrusive Javascript Image Rollovers(0)
  7. Dynamicdrive: Good Site For JavaScript Codes(5)
  8. Downloads With Javascript?(7)
  9. Javascript: Simple Slidedown Menu(2)
  10. JavaScript: Simple Dropdown Menu(1)
  11. Calling Of Functions Between Mulitple External Javascript Files(2)
  12. Javascript: Browser Detection Script(0)
  13. JavaScript: Hide And Show Any Element With CSS(5)
  14. Ever Needs To Find Out A Table Height Or With With JavaScript(2)
  15. Create And Import JavaScript Modules For A Large Script(2)
  1. Vertical Marquee Using JavaScript(0)
  2. JavaScript Frames & Querystring(4)
  3. JavaScript Off Redirect Script(2)
  4. I Need Help With Javascript.(6)
  5. Problems With Dynamically Loading Javascript(2)
  6. Add Text To Textarea(6)
  7. Javascript Question(4)
  8. Javascript: How Do I Create Embedded Pop-up Windows?(7)
  9. Problem With Javascript Alert();(9)
  10. Include Function For Javascript(6)
  11. Fun With Javascript And Forms(2)
  12. Javascript Help Needed : Alert(z) Works Fine But Document.write Not(2)
  13. Javascript Changes Aren't Working.(6)


 



- Lo-Fi Version Time is now: 5th July 2008 - 11:56 PM