Go Premium for a chance to win a PS4. Enter to Win

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
?
239 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
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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

972 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