[Project_owners] How to get selected text (Solved it)

Jaap A. Haitsma jaap at haitsma.org
Fri Mar 19 14:17:38 EST 2004



> Jaap A. Haitsma wrote:
>
>> if ((nodeLocalName == "TEXTAREA") ||
>>     (nodeLocalName == "INPUT" && node.type == "text")) {
>
> Ideally you would use node instanceof HTMLTextAreaElement (or
> HTMLInputElement) instead of checking the node's local name.

Thanks didn't know that it could be done like that.

>>     selection =
>> focusedWindow.__proto__.getSelection.call(focusedWindow).toString();
>
> I wondered why you messed around with __proto__, but even
> nsContextMenu.js does it, sigh...

I also found this __proto__ quite funky but saw that it was used in the
mozilla code as well.
Do you know the reason why it's being used?


>
>> selection = selection.toString();
>
> It should already be a string by now :-P

Thought the same, but I basically copied the code from the text/plain
extension and that worked :-). Didn't bother to optimize it till now.

Jaap


More information about the Project_owners mailing list