473,395 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

firefox page element without getComputedStyle

I thought that this was available for all elements in Firefox, but
recently had a page where a div didn't have it. I put in an id style
for it, thinking that would do the trick, but it didn't.

Is that something that isn't there for all elements that are correctly
formed, or possibly something that disappears due to malformed HTML? Or
is there any other code-related reason (i.e., mistake) that causes it to
disappear?
Dec 30 '06 #1
4 2776
Steve wrote:
I thought that this was available for all elements in Firefox, but
recently had a page where a div didn't have it. I put in an id style
for it, thinking that would do the trick, but it didn't.
Please post the specific code that failed for you, your subject mentions
getComputedStyle but your post does not show us how you tried to use
that and what exactly failed.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 31 '06 #2
Martin Honnen wrote:
Steve wrote:
>I thought that this was available for all elements in Firefox, but
recently had a page where a div didn't have it. I put in an id style
for it, thinking that would do the trick, but it didn't.

Please post the specific code that failed for you, your subject mentions
getComputedStyle but your post does not show us how you tried to use
that and what exactly failed.

Sorry, I guess I have been misusing getComputedStyle. I have been using
it as elt.getComputedStyle(), which actually works for some elements on
my page, as opposed to document.defaultView.getComputedStyle(elt, null).

I suppose a better original question would have been "Why do some
elements have a getComputedStyle method available" as opposed to the
opposite.

But it doesn't matter anyway, as things turned out; what I wanted to
retrieve was the value of 'top' so I could position a hidden div with a
dialog box-looking form at an appropriate spot, but "auto" just isn't
going to cut it for that purpose.
Jan 1 '07 #3
Steve wrote:
Martin Honnen wrote:
>Steve wrote:
>>I thought that this was available for all elements in Firefox, but
recently had a page where a div didn't have it. I put in an id style
for it, thinking that would do the trick, but it didn't.

Please post the specific code that failed for you, your subject
mentions getComputedStyle but your post does not show us how you tried
to use that and what exactly failed.

Sorry, I guess I have been misusing getComputedStyle. I have been using
it as elt.getComputedStyle(), which actually works for some elements on
my page, as opposed to document.defaultView.getComputedStyle(elt, null).

I suppose a better original question would have been "Why do some
elements have a getComputedStyle method available" as opposed to the
opposite.

But it doesn't matter anyway, as things turned out; what I wanted to
retrieve was the value of 'top' so I could position a hidden div with a
dialog box-looking form at an appropriate spot, but "auto" just isn't
going to cut it for that purpose.
A revised question is: why do some elements in Firefox have their own
getComputedStyle() method, taking no arguments and yielding the
properties for that element, while others do not? (I use it to get the
original display property for a table row, so I can put it back to
unhide it.)

And, a bit of a flame -- I realize that might be some value to the
current behavior of the more global getComputedStyle, but:

1. it seems pretty useless to anything but internal code for the
browser. Most peoples' in-page code is not going to care that the
result of inheriting down the cascade of styles yields something like
'auto'. Maybe code to snip a element off the tree and put the node
somewhere else might care about things like that, but otherwise I can't
think of code that I would write that would need that information.

There really ought to be a method to do what most people want to do --
calculate the actual resulting positions, colors, etc., that result from
the element being displayed on the page.

So we get forced into things like the nice script available at
http://www.quirksmode.org/js/findpos.html, but that seems to break a
fundamental principle of OOP -- that a programmer should not be
concerned with the inner workings of an object; rather they should be
able to treat it as a "black box". So I shouldn't have to work my way
up the containment tree to find a position. The browser has already done
that; I know, I see the element at a position on the page, and obviously
the browser put it there.

2. getting 'auto' as the result hasn't 'computed' anything, so why the
name of the method? getDerivedStyle or or something like that would
seem to be a better name.
Jan 5 '07 #4
VK

Steve wrote:
Sorry, I guess I have been misusing getComputedStyle. I have been using
it as elt.getComputedStyle(), which actually works for some elements on
my page, as opposed to document.defaultView.getComputedStyle(elt, null).
document.defaultView returns a reference to the semi-mysterious
AbstractView interface - "a base interface that all views shall derive
from"
<http://www.w3.org/TR/DOM-Level-2-Views/views.html#Views-AbstractView>

So AbstractView (==document.defaultView) is that imaginary container
where HTML element and anything inside of it resides and being viewed
on the screen, something that is contained by nothing by contains
everything. As a "DOM equivalent of God" :-) it did suppose to know of
how anything looks like at any spot of the viewport.
On practice - as you already discovered - its current
(under)implementation across UA's leaves more to desire.

But even in its current state it may be useful, at least it is much
more useful than IE's currentStyle.

See for example how easy to find - using getComputedStyle - one of the
most important values: the actual pixel equivalent of 1em for the given
container (and compare it with IE's data):

<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<style type="text/css">
p {
font-size: 1em;
}
</style>
<script type="text/javascript">
function init() {
var p = document.getElementsByTagName('p')[0];
var em = null;
if (document.defaultView) {
em = document.defaultView.getComputedStyle(p,null).font Size;
alert(em);
}
else if (p.currentStyle) {
em = p.currentStyle.fontSize;
alert(em);
}
else {
'NOP';
}
}
window.onload = init;
</script>
</head>
<body>
<p>M</p>
</body>
</html>
<speculation>
I am not sure where did the elementReference.getComputedStyle support
come from. My guess would be that some producers (W3C?) wanted to
provide a possibility to make the code more "visually close" to IE with
its elementReference.currentStyle.
This attempt though seems as dropped at the middle.
</speculation>

1. it seems pretty useless to anything but internal code for the
browser. Most peoples' in-page code is not going to care that the
result of inheriting down the cascade of styles yields something like
'auto'. Maybe code to snip a element off the tree and put the node
somewhere else might care about things like that, but otherwise I can't
think of code that I would write that would need that information.

There really ought to be a method to do what most people want to do --
calculate the actual resulting positions, colors, etc., that result from
the element being displayed on the page.

So we get forced into things like the nice script available at
http://www.quirksmode.org/js/findpos.html, but that seems to break a
fundamental principle of OOP -- that a programmer should not be
concerned with the inner workings of an object; rather they should be
able to treat it as a "black box". So I shouldn't have to work my way
up the containment tree to find a position. The browser has already done
that; I know, I see the element at a position on the page, and obviously
the browser put it there.

2. getting 'auto' as the result hasn't 'computed' anything, so why the
name of the method? getDerivedStyle or or something like that would
seem to be a better name.

That is a bleeding problem of the current DOM and I do sign under each
word. I do not understand why an everyday obvious task would require
sophisticated programs like the one on Quirksmode or even more
sophisticated (but more robust) at
<http://www.javascripttoolbox.com/lib/objectposition/>

Iin more than 10 years no one managed to provide anything reasonable on
the matter. It suggests that there is some core problem in how DOM and
graphics context have to communicate with each other: which requires
either write an all new software from the scratch - or to leave
developers with all these crappy and obscure offsetHere/offsetThere

Jan 5 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: delerious | last post by:
I need to determine an element's width and height in pixels (not including padding, border, and margin) in Javascript. The element will not have width or height styles specified. In Mozilla, I...
22
by: DJ WIce | last post by:
Hi, I'm looking for a script to get the hi-est z-index on a page. I want my javascript menu to be always on top of the page (moves along on top when you scroll down). Does anyone know how to...
5
by: Martin Chen | last post by:
I have a frame set (as per MS FrontPage 2000). It has a contents and a main frame. The contents frame has a menu bar written with with javascript (in the context of a table). In IE6.1 everything...
2
by: awoodgate | last post by:
Hi, I'm trying to read the width of a css absolutely positioned element in javascript. If I use an id selector or a class definition then the width is null, but if I use an inline style then it...
4
by: petermichaux | last post by:
Hi, I'm curious why the follow little HTML page produces "auto" for JavaScript output. I thought that getComputedStyle() was supposed to return integer px values for lengths. Is this a problem...
2
by: Pugi! | last post by:
I would like to obtain the the position of backgroundimage of a div because I use it for animation. The following code works for Internet Explorer (takes the else if) and returns positionx '10px'...
4
by: Paul Fi | last post by:
im trying to change the width of an object dynamically, this i s the object inside an html form input name="btnEmpty" id = "btnempty" type="button" class="" value=""
9
by: =?Utf-8?B?Sm9obiBCYWlsZXk=?= | last post by:
I have a ASP .Net page that allows moving around items on the page through javascript. This page works fine in IE. In FireFox however, I have found that if the page is using XHTML 1.0...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.