Open
Bug 663753
Opened 14 years ago
Updated 5 years ago
The "onunload" javascript event fires during the initial loading of the page, when a charset is specified with the Content-Type meta tag
Categories
(Core :: DOM: HTML Parser, defect, P5)
Tracking
()
UNCONFIRMED
People
(Reporter: serge45, Unassigned)
References
()
Details
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Build Identifier: Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
HTML file used : The head section of the html document contains a javascript which catches the onunload event and displays a popup with alert(). It is followed by a Content-Type meta tag specifying the use of iso-8859-1. The body section contains at least one character from the above part of the charset (code is > 0x80).
Behavior : the onunload event is fired (the popup displays) during the page loading, it should not.
Reproducible: Always
Steps to Reproduce:
1. create a new tab in Firefox (Ctrl+T)
2. enter http://v4.calnatation.fr/onunload_on_load.html in the address bar
3. close the tab by clicking on the cross icon
Actual Results:
The popup saying "onUnload fires !" displays immediately.
The popup displays a second time when the page is unloaded, by closing the tab, or by clicking on the link to about:blank which is provided in this page.
Expected Results:
The popup should not display at the first time, but only at the second time when the page is unloaded.
Source code of the page "onunload_on_load.html" used to reproduce this bug.
Please note that the bug does not appear when one of the following condition is met :
- the meta tag is placed before the javascript
- no exotic character (>0x80) from the charset is used
- the javascript code is shorter (less than 1k byte ?)
-------------------------------------------------------
<html>
<head>
<title>TEST</title>
<script type="text/javascript">
// The javascript code should be a little big
// abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
// abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
// abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
// abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
// abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
// abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
// abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
// abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
// abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
// abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
// abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
// abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
// abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
// abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
// abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
// abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
// abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
// abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
function WarnUser(){
alert("onUnload fires !");
}
onunload = WarnUser;
</script>
<!-- Declare Content-Type with the latin-1 charset -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
The body contains a character from the above part of the iso-8859-1 charset (here, the french e-acute 0xE9 is used) : é
<br>
Dummy link to unload the page : <a href="about:blank">[about:blank]</a>
</body>
</html>
![]() |
||
Comment 1•14 years ago
|
||
You're seeing a charset change reload due to a <meta> tag that comes too late in the buffer (in particular, after the HTML5 prescan limit, so the script has run, then the <meta> is seen, the charset changes, and the document has to be reloaded with the new charset).
So I believe this is invalid.
Note that the markup is _definitely_ invalid per spec: that <meta> tag is only allowed as the first child of <head>.
Component: Event Handling → HTML: Parser
QA Contact: events → parser
I agree on the fact that the meta should definitively be placed earlier in the head. But please consider that :
- there are probably a lot of web pages with this kind of late charset change
- the demo html source is an abstract of the real html generated by one of my website powered by Joomla (onunload event used when in edit mode)
- I had no problem with the previous versions of Firefox (3.x)
- the HTML 4.01 specification says in 5.2.2 (http://www.w3.org/TR/html4/charset.html#spec-char-encoding) that "META declarations should appear as early as possible in the HEAD element", that's less strict than "first child"
- the html source passes successfully the http://validator.w3.org, when adding HTML4.01 doctype and other mandatory stuff (this completed version is in http://v4.calnatation.fr/onunload_on_load_v2.html)
![]() |
||
Comment 3•14 years ago
|
||
> - there are probably a lot of web pages with this kind of late charset change
There are some, sure.
> - I had no problem with the previous versions of Firefox (3.x)
The size of the meta prescan buffer has changed, yes. The new buffer size is the one required by the HTML5 specification.
> the HTML 4.01 specification says
That's been superseded by HTML5.
Comment 4•5 years ago
|
||
Bulk-downgrade of unassigned, >=5 years untouched DOM/Storage bugs' priority.
If you have reason to believe this is wrong (especially for the severity), please write a comment and ni :jstutte.
Severity: normal → S4
Priority: -- → P5
You need to log in
before you can comment on or make changes to this bug.
Description
•