Closed Bug 307783 Opened 15 years ago Closed 15 years ago

[FIX]Javascript window.find fails to find text unless an alert is executed before the find

Categories

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

defect

Tracking

()

RESOLVED FIXED
mozilla1.9alpha1

People

(Reporter: rwenger, Assigned: bzbarsky)

Details

(Keywords: fixed1.8.1)

Attachments

(2 files)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6

Window.find fails to find text on the page most of the time.  I discovered that
putting up an alert box containing arbitrary text before the window.find
statement causes the find to succeed. 

Reproducible: Always

Steps to Reproduce:
1. Make a web page with the following content.
<html>
<head>
<title>Test page</title>
</head>
<body>
<H1>
	Test page for Mozilla FireFox.
</H1>
</body>
<SCRIPT>

	alert('any text');

	var string1 = window.find('Mozilla');
</SCRIPT>
</html>

2. Load the page with Mozilla or FireFox, click OK on the alert box, and notice
that 'Mozilla' is hi-lighted.

3. Comment out or remove the alert line, then reload the page.  'Mozilla' is not
found.

Actual Results:  
When an alert statement preceeds window.find, the search is successful.
When the alert is removed, the search fails.

Expected Results:  
Window.find should search the page regardless of the presence of an alert
statement.  

The example above fails reliably.  In a complex production environment, SFX, it
fails most of the time, but occasionally succeeds.
I can "confirm" this in FF 1.5 Beta 1, but it seems merely that the javascript
is poorly written.  The fix for this is very easy.  I'm only guessing here, but
window.find doesn't start to work until the document finishes.  So just write
the code:

<script type="text/javascript">
onload = function() { window.find('Mozilla'); }
</script>
It's not quite as simple as that.  I need to conditionally insert a link at the
end of the page based on the presence or absence of text already included in the
page previous to the script. 
-Rich  
try:
<SCRIPT>
    document.body.offsetHeight;
    var string1 = window.find('Mozilla');
</SCRIPT>

You need to force gecko to reflow the page it has received so far.
==> DOM
Assignee: general → general
Component: General → DOM
Product: Mozilla Application Suite → Core
QA Contact: general → ian
Version: unspecified → Trunk
Attached patch Proposed fixSplinter Review
Assignee: general → bzbarsky
Status: UNCONFIRMED → ASSIGNED
Attachment #207686 - Flags: superreview?(jst)
Attachment #207686 - Flags: review?(jst)
OS: Windows XP → All
Priority: -- → P3
Hardware: PC → All
Summary: Javascript window.find fails to find text unless an alert is executed before the find → [FIX]Javascript window.find fails to find text unless an alert is executed before the find
Target Milestone: --- → mozilla1.8.1
Comment on attachment 207686 [details] [diff] [review]
Proposed fix

r+sr=jst
Attachment #207686 - Flags: superreview?(jst)
Attachment #207686 - Flags: superreview+
Attachment #207686 - Flags: review?(jst)
Attachment #207686 - Flags: review+
Comment on attachment 207686 [details] [diff] [review]
Proposed fix

It might be worth taking this for 1.8.1.  I think this should be safe (esp. with some bake time).
Attachment #207686 - Flags: approval1.8.1?
Fixed on trunk.
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Target Milestone: mozilla1.8.1 → mozilla1.9alpha
Attachment #207686 - Flags: approval1.8.1? → branch-1.8.1?(jst)
Attachment #207686 - Flags: branch-1.8.1?(jst) → branch-1.8.1+
Fixed on branch.
Keywords: fixed1.8.1
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.