On Sat, Feb 12, 2011 at 1:56 PM, clothears <[email protected]> wrote:
> Are there any issues with setting window.innerWidth? Using Safari > 5.0.3 Mac I'm finding that if I set it to some value, then that is the > value it subsequently reports, however much the window is resized. > I would regard innerWidth as a read-only property. I know there are various inconsistencies with innerWidth between browsers, but don't know them by heart. Maybe somebody else (or google) does. > It appears that if I set some value using CSS, then I am unable to > read that value with JavaScript. I have, instead, to not bother > setting it with CSS, but instead to initialise it (to the same value) > with JavaScript, and then I find I can read it back correctly. Is this > expected behaviour? > Yes. I'm assuming you're trying to read these values through the el.style object. This is safe for writing, but not for reading. To read (any currently applied style for a specific element), there are two ways to go: non-IE: see el.getComputedStyle. For example, document.defaultView().getComputedStyle(el,null).getPropertyValue(styleName); Note that styleName is a string and the css property with dashes. IE: see el.currentStyle[styleName]; For IE, the styleName must be the camel cased version of the css property name you want to query. You'll still need to normalize the returned values (eg, remove px or convert %). - peter -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
