Inline scripts in XHTML can't set focus (workaround: setTimeout)

RESOLVED FIXED

Status

()

Core
DOM: Core & HTML
RESOLVED FIXED
14 years ago
11 years ago

People

(Reporter: dzy, Unassigned)

Tracking

({testcase, xhtml})

Trunk
testcase, xhtml
Points:
---
Dependency tree / graph
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [ignore comments 4-8])

Attachments

(2 attachments, 2 obsolete attachments)

(Reporter)

Description

14 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113

this minimal test case worked in 1.5 and 1.6a, the input field gets focus after
page load, but not in 1.6b and 1.6 final.

test.xhtml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>
<form action="http://www.google.com/search" id="f">
<input maxlength="256" size="55" name="q" />
</form>
<script type="text/javascript">
<![CDATA[
document.getElementById("f").q.focus();
]]>
</script>
</body>
</html>


Reproducible: Always

Steps to Reproduce:
1.
2.
3.

Actual Results:  
the input field doesn't get focus

Expected Results:  
the input field gets focus after page load
Not a JS engine bug.  Please don't file bugs in random DOM functionality on the
JS engine....
Assignee: general → general
Component: JavaScript Engine → DOM: Level 0
QA Contact: PhilSchwartau → ian
Created attachment 139777 [details]
testcase
Are you sure this worked in 1.6a?  I just tried builds back to July and in none
of them does the textfield have focus.... (all on Linux).  For that matter, it
doesn't work in non-XHTML documents either; things work fine if the focus() call
is made from onload(), though.

Comment 4

14 years ago
Created attachment 144835 [details]
Testcase v2

Comment 5

14 years ago
Created attachment 144836 [details]
Testcase v3

Comment 6

14 years ago
Testcases v2 and v3 WORKFORME in Mozilla 1.7b 2004032208 and Firefox 0.8
20040206 under XP Pro SP1. The use of 
<![CDATA[
... unescaped script content ...
]]>
is only needed if the javascript code uses <, > and & characters. The // is to
indicate that the <!CDATA[ and ]]> strings are actually not part of the
javascript code. So,

<script type="text/javascript">
document.getElementById("q").focus();
</script>
in Testcase v2 and

<script type="text/javascript">
document.getElementById("f").q.focus();
</script>
in Testcase v3
also WORKFORME.

I'm all for RESOLVING this bug as INVALID or WORKSFORME.
Keywords: testcase
Those last two attachments aren't XHTML.  This but is only an issue in XHTML,
not HTML.

The bug is most definitely present, not matter what you're all for.
Whiteboard: [ignore comments 4-7]
Attachment #144835 - Attachment is obsolete: true
Attachment #144836 - Attachment is obsolete: true

Comment 8

14 years ago
>Those last two attachments aren't XHTML.
Sorry I got that wrong.

Updated

14 years ago
Keywords: xhtml
OS: Windows XP → All
Hardware: PC → All
Whiteboard: [ignore comments 4-7] → [ignore comments 4-8]
At a guess, the problem is that the focus() call happens before layout has
started, so there is no layout object to focus (non-incremental content sink and
all that).....

Updated

12 years ago
Summary: xhtml javascript set focus doesn't work → Inline scripts in XHTML can't set focus (workaround: setTimeout)
Depends on: 18333

Comment 10

12 years ago
Marking NEW based on bz's comments and the fact that his testcase does in fact fail.
Status: UNCONFIRMED → NEW
Ever confirmed: true

Comment 11

11 years ago
Fixed by bug 18333?  The blinking caret is mysteriously misplaced (it appears at the end of the textbox rather than at the beginning) but typing into the textbox works normally.

Comment 12

11 years ago
I think the caret bogosity is an unrelated regression.  See bug 368861.
Depends on: 368893
Flags: in-testsuite?
Created attachment 257001 [details] [diff] [review]
Mochitest testcase
Fixed by checkin for 18333.  Added the test.
Status: NEW → RESOLVED
Last Resolved: 11 years ago
Flags: in-testsuite? → in-testsuite+
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.