Can you get selected text from a parent?

S

smerf

If I have an iFrame on a webpage, and a user selects text or objects in the
parent of my iFrame, how can I get the selected text or objects properties
from my iFrame child?
 
M

Martin Honnen

smerf said:
If I have an iFrame on a webpage, and a user selects text or objects in the
parent of my iFrame, how can I get the selected text or objects properties
from my iFrame child?

In general how the browser exposes a text selection to script is highly
browser dependent.
Mozilla and by now Opera 9 expose a selection object per window that you
can access as
if (typeof window.getSelection != 'undefined') {
var selection = window.getSelection();
}
respective for the iframe then
if (window != parent && typeof parent.getSelection != 'undefined') {
var selection = parent.getSelection();
}
One documentation for that selection object is here:
<http://www.xulplanet.com/references/objref/Selection.html>
 
S

smerf

Sweet! Thanks for the help, Martin.

Martin Honnen said:
In general how the browser exposes a text selection to script is highly
browser dependent.
Mozilla and by now Opera 9 expose a selection object per window that you
can access as
if (typeof window.getSelection != 'undefined') {
var selection = window.getSelection();
}
respective for the iframe then
if (window != parent && typeof parent.getSelection != 'undefined') {
var selection = parent.getSelection();
}
One documentation for that selection object is here:
<http://www.xulplanet.com/references/objref/Selection.html>
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top