[Webkit-unassigned] [Bug 7275] New: window.getSelection() doesn't work in textareas
bugzilla-daemon at opendarwin.org
bugzilla-daemon at opendarwin.org
Wed Feb 15 08:40:34 PST 2006
http://bugzilla.opendarwin.org/show_bug.cgi?id=7275
Summary: window.getSelection() doesn't work in textareas
Product: WebKit
Version: 420+ (nightly)
Platform: Macintosh
OS/Version: Mac OS X 10.4
Status: UNCONFIRMED
Severity: major
Priority: P2
Component: JavaScript
AssignedTo: webkit-unassigned at opendarwin.org
ReportedBy: stamm at salesforce.com
window.getSelection() returns null when the selection is in a text area. This
behavior makes it very difficult when there are two text areas on the page.
Since the selection for a text area remains when you leave it, you have no idea
which one of the text areas is the current (or last one) selected.
In the latest nightly build, when I try the page below, if you select the
"Random Text" and then click dump range, you will get a real range object. If
you select the "My text" inside the text area, you get null for a range object.
You can fake it using getSelectionRange, but that doesn't work.
1. Select "text" inside the text area
2. Select "random"
3. Click "Copy TextArea Sel". This contains the last selection. Even though
random was selected.
If I would add another text area, I would have no idea what the user has
selected
<html>
<head>
<meta http-equiv="Content-type" content="text/html" />
<title>Simple Selection Test</title>
<script>
function dumpO(o) {
var msg = "";
var i = 0;
for (var f in o) {
try {
msg += f + " = " + o[f] + "\n";
} catch (e) {}
if (i++ == 10) {
i=0;
alert(msg);
msg = "";
}
}
if (msg) alert(msg);
}
function getSelectionRange(o) {
var start = o.selectionStart;
var end = o.selectionEnd;
return o.value.substring(start,end);
}
</script>
</head>
<body>
<button onclick="document.getElementById('r').innerHTML =
window.getSelection();"><u>Copy Window Sel</u></button><br>
<button onclick="document.getElementById('r').innerHTML =
getSelectionRange(document.getElementById('text'));"><u>Copy
TextArea Sel</u></button><br>
<button onclick="dumpO(window.getSelection());"><u>Dump
Selection</u></button><br>
<button onclick="dumpO(window.getSelection().getRangeAt(0));"><u>Dump
Range</u></button><br>
<button onclick="document.getElementById('r').innerHTML =
window.getSelection().getRangeAt(0);"><u>Copy Range</u></button><br>
<button onclick="dumpO(document.getElementById('text'));"><u>Dump
TextArea</u></button><br>
<button onclick="dumpO(window);"><u>Dump Window</u></button><br>
<textarea id="text" name="text" rows="20" cols="80"/>
My text</textarea>
<div id="r">divMe</div>
Random Text
</body>
</html>
--
Configure bugmail: http://bugzilla.opendarwin.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
More information about the webkit-unassigned
mailing list