Solved

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

Posted on 2011-03-15
2
234 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 500 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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

632 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