Jump to content
xisto Community
OpaQue

Getting Screen Resolution using Javascript.

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

<{POST_SNAPBACK}>


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:

 

<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

Share this post


Link to post
Share on other sites

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:
<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:
$_GET['scrw']$_GET['scrh']

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Getting "viewing area" sizeGetting Screen Resolution using Javascript.

toby, you're totally wrong.

Jared, you can use window.InnerWidth and window.InnerHeight ... Have fun! ;)

-reply by Matteo

Share this post


Link to post
Share on other sites
Not workingGetting Screen Resolution using Javascript.

None of the variables I've seen have worked at all. The most I've seen is undefinedxundefined.

I've tried:  window.InnerWidth, screen.Width, screen.AvailWidth

 I'm first off just trying to get it to work in a pop up before I use it.

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

-reply by Clint

Share this post


Link to post
Share on other sites
How to get the usable Screen Size from your visitor into a PHP variable using Javascript.Getting Screen Resolution using Javascript.

"Is there a way to get the height and width of the viewing area "Create a php page named 'screen.Php' and include the php script<?phpEcho $_GET['scrw'];Echo $_GET['scrh'];?>Then create another PHP or HTML page with this javascript and name it whatever you wish...Such as 'MyCreenTest.Php'Click here to tell what me your screen size is!Run MyCreenTest.Php and click the link and the link will go to 'screen.Php', which will display your usable screen size from a php echo. If you are going to use this throughout your site, you might should place them in a session var such as$_SESSION['scrW'] = $_GET['scrw'];$_SESSION['scrH'] = $_GET['scrh'];And that will do itNow...Can someone tell me how to redirect to the screen.Php page without stopping and asking the user to click somthing?

Thanks-reply by Douglas

 

Share this post


Link to post
Share on other sites
How to get the usable Screen Size from your visitor into a PHP variable using Javascript.Getting Screen Resolution using Javascript.

I just wonder, why using a PHP function when the actual functionality depends fully on JavaScript?

<script>document.Write(IMG code with JavaScript_screen() filled variables)</script>

<noscript><IMG safe screen default modus></noscript>

Natuarlly, you could use PHP to fill in the imagenames etcetera in both situations and a call to the function like : JavaScript_screen(<?php echo original imagewidth; ?>) {return var the_width_you_need}

-reply by PortalPress.Org

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.