Closed Bug 304142 Opened 20 years ago Closed 20 years ago

document.body.clientHeight seems to be wrong when resizing window

Categories

(Firefox :: General, defect)

x86
Windows 2000
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 297284

People

(Reporter: jsgoupil, Unassigned)

Details

Attachments

(3 files, 1 obsolete file)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; fr-FR; rv:1.7.10) Gecko/20050717 Firefox/1.0.6 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; fr-FR; rv:1.7.10) Gecko/20050717 Firefox/1.0.6 When trying to resize an applet with JavaScript function, the applet reduces and disappear from the browser. It seems that when not using xhtml norms, the applet resize correctly. In fact, it seems that document.body.clientHeight is wrong with the norms. Reproducible: Sometimes Steps to Reproduce: 1. Create a red background applet : import java.awt.Color; import javax.swing.JApplet; import javax.swing.JPanel; /* * Created on 2005-08-10 */ /** * @author Jean-Sébastien Goupil */ public class test extends JApplet{ public void init(){ } public void start(){ JPanel pan = new JPanel(); pan.setBackground(Color.red); this.getContentPane().add(pan); } } 2. Create jar (test.jar) 3. Create an HTML webpage that resizes the applet when resizing the window with XHTML norms. Opened in a new window (no tab) <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>test</title> </head> <body> <applet code="test.class" id="bleh" archive="test.jar" width="300" height="200"> </applet> <script type="text/javascript"> function haha() { document.getElementById('bleh').width = document.body.clientWidth - 35; document.getElementById('bleh').height = document.body.clientHeight - 35; alert(document.body.clientHeight); } window.onresize = haha; </script> </body> </html> Actual Results: The applet is reducing his height always when resizing the window and disappear when the height is too short. Expected Results: Resize normally The clientheight seems to be 0 if nothing is in the webpage. So if it is a problem with the code of clientHeight, why does clientWidth is not doing the same thing (reducing and desappearing) ?
Please attach a compiled .jar and the html page to this bug.
Attached file testcase (obsolete) —
Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8b4) Gecko/20050810 Firefox/1.0+ ID:2005081009 wfm with a testcase using a div (open testcase and resize the page) shouldn't you use document.getElementById('bleh').style.width i/o document.getElementById('bleh').width ?
Attached file Jar file
Attached file HTML call file
I can't use style.width because it is an applet... but the problem is not there, it is with the XHTML standard.
(In reply to comment #5) > I can't use style.width because it is an applet... but the problem is not there, > it is with the XHTML standard. yeah, document.body.clientHeight consistently keeps returning 0 once you've resized the applet to the point
Attached file testcase
proper testcase with <div> showing the behaviour
Attachment #192238 - Attachment is obsolete: true
(W/r/t Peter's latest testcase.) Not a bug. clientHeight is offsetHeight in standards mode (http://www.quirksmode.org/viewport/compatibility.html). The offsetHeight is 100px, because the only element on the page is 100px. Resize once: goes to 50px. Resize again: 0px.
So why the width is not doing the same thing ?
Severity: major → normal
*** This bug has been marked as a duplicate of 297284 ***
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → DUPLICATE
The only element is a display:block element. display:block elements always expand to the greatest size possible, which is the window width, so clientWidth behaves like you want it to.
I'm also opposed to this bug being marked as a duplicate to something else (especially to an unconfirmed bug) since, as quirksmode states, this is clearly not a bug at all (invalid would be better).
(In reply to comment #11) > The only element is a display:block element. display:block elements always > expand to the greatest size possible, which is the window width, so clientWidth > behaves like you want it to. <body> is the block element, not <div>. Sorry for the confusion.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: