Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Trying to find a cross broswer solution to find either the screen resolution or browser resolution.

Posted on 2011-03-15
2
Medium Priority
?
237 Views
Last Modified: 2012-05-11
$(window).width();   // returns width of browser viewport
$(document).width(); // returns width of HTML documentI have a php site that needs to know the screen resolution OR the browser resolution to correctly place an absolute position <div></div>

The OS's are OSX 10.6, WinXp Pro, Win 7 Pro
Browsers are IE6,IE7,IE8,IE9,Safari>5,misc firefox ..

I can get document.width/document.height to work in safari.
I can't get it to work in IE

I can get mild success with the jquery library in IE, but not safari
(http://api.jquery.com/width/ :::
$(window).width();   // returns width of browser viewport
$(document).width(); // returns width of HTML document
)

What works all over the place ??
0
Comment
Question by:Imaginx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Expert Comment

by:Mark Brady
ID: 35142019
I don't think there is a cross browser solution sorry. At least I have never seen one. That's why you should use a conditional query to see which browser is being used, then set the right code depending on what browser they have.

<!--[if IE 6]>
// put IE6 code in here
<![endif]-->
and so on for all the other browsers.
0
 
LVL 9

Accepted Solution

by:
EZFrag earned 2000 total points
ID: 35144947
Hi there,

You could try the snippet below. It might just work....

Hope it helps ^_^
var width,height;
if (self.innerHeight) // all except Explorer
{
	width = self.innerWidth;
	height = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
{
	width = document.documentElement.clientWidth;
	height = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
	width = document.body.clientWidth;
	height = document.body.clientHeight;
}

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question