Closed Bug 232004 Opened 21 years ago Closed 17 years ago

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

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: dzy, Unassigned)

References

Details

(Keywords: testcase, xhtml, Whiteboard: [ignore comments 4-8])

Attachments

(2 files, 2 obsolete files)

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
Attached file 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.
Attached file Testcase v2 (obsolete) —
Attached file Testcase v3 (obsolete) —
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
>Those last two attachments aren't XHTML.
Sorry I got that wrong.
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).....
Summary: xhtml javascript set focus doesn't work → Inline scripts in XHTML can't set focus (workaround: setTimeout)
Marking NEW based on bz's comments and the fact that his testcase does in fact fail.
Status: UNCONFIRMED → NEW
Ever confirmed: true
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.
I think the caret bogosity is an unrelated regression.  See bug 368861.
Depends on: 368893
Flags: in-testsuite?
Fixed by checkin for 18333.  Added the test.
Status: NEW → RESOLVED
Closed: 17 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.

Attachment

General

Created:
Updated:
Size: