Get the highlighted text within an iframe with Firefox 3.5

D

DL

I thought document.getElementById
('frameID').contentWindow.document.selection.createRange().text
should do it. However, it no longer works. What's the correct
syntax?

Thanks.
 
T

Thomas 'PointedEars' Lahn

DL said:
I thought document.getElementById
('frameID').contentWindow.document.selection.createRange().text
should do it.

This could be shortened to the more standards-compliant

document.getElementById('frameID').contentDocument.selection.createRange().text

For it to work in Gecko-based browsers, though, it always needed to be

document.getElementById('frameID').contentDocument.getSelection()

which returns the selected text (for highlighted images: the alternative
text) as a string value, or

document.getElementById('frameID').contentWindow.getSelection()

or the more standards-compliant

document.getElementById('frameID').contentDocument.defaultView.getSelection()

which both return a proprietary Selection object.

Recently also supported is the following feature specified in W3C DOM Level
2 Range:

document.getElementById('frameID').contentDocument.createRange().toString()
However, it no longer works.

Your approach has never worked in Firefox as neither the Gecko DOM nor the
W3C DOM support a `selection' property on Document objects; it is MSHTML-
proprietary.

Do not forget to put your question in the message body next time.


PointedEars
 
D

DL

This could be shortened to the more standards-compliant

  document.getElementById('frameID').contentDocument.selection.createRange().text

For it to work in Gecko-based browsers, though, it always needed to be

  document.getElementById('frameID').contentDocument.getSelection()

which returns the selected text (for highlighted images: the alternative
text) as a string value, or

  document.getElementById('frameID').contentWindow.getSelection()

or the more standards-compliant

  document.getElementById('frameID').contentDocument.defaultView.getSelection()

which both return a proprietary Selection object.

Recently also supported is the following feature specified in W3C DOM Level
2 Range:

  document.getElementById('frameID').contentDocument.createRange().toString()


Your approach has never worked in Firefox as neither the Gecko DOM nor the
W3C DOM support a `selection' property on Document objects; it is MSHTML-
proprietary.

Do not forget to put your question in the message body next time.

PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
  -- Richard Cornford, cljs, <[email protected]>

Beautiful (it works). Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,082
Messages
2,570,587
Members
47,209
Latest member
Ingeborg61

Latest Threads

Top