JS comparing innerHTML to text selection (window.getSelection() /document.selection)

A

Andrew Crowe

Hi,

I've got a function to get data from a text selection in a users browser:

function class_getSelection(){
if (browser.isIE5up) {
return EpozElement.contentWindow.document.selection;
} else {
return EpozElement.contentWindow.window.getSelection();
};
}



I've then got functions that get the parent tag from the selection:


function class_getSelectionRange(){
sel = class_getSelection();
if (browser.isIE5up) {
return sel.createRange();
} else {
return sel.anchorNode;
};
}
function class_getSelectionParent(){
range = class_getSelectionRange();
if (browser.isIE5up) {
return range.parentElement();
} else {
return range.parentNode;
};
}


From this I'd like to find out if the user's selection covers the
entire tag (eg. they've highlited an entire paragraph) or just a
sentence in the paragraph). I've tried

selection=class_getSelection();
object=class_getSelectionParent();
if(selection==object.innerHTML)

but unfortunately selection is just the text and innerHTML includes html
tags / special breaks etc. Is there any way to compare selection and
innerHTML to work out whether they point to the same thing (eg. the user
has highlited the entire block).


Thanks
Andrew
 
A

Andrew Crowe

I've got a function to get data from a text selection in a users browser:

After working on this for a bit what I would really like is a way to
read the HTML from a users selection, rather then just the text as

function class_getSelection(){
if (browser.isIE5up) {
return EpozElement.contentWindow.document.selection;
} else {
return EpozElement.contentWindow.window.getSelection();
};
}

returns.


I've tried adding innerHTML to the sel.createRange()/sel.anchorNode but
that doesn't work unfortunatly


Thanks

Andrew
 

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
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top