views:

104

answers:

1

Hi all,

I'm trying to highlight the selected text contents by the user inside the HTML page I loaded using PHP + XSL transformation. I have seen some solutions related with highlighting current selected text, but I need to save some information to the database that makes me able to highlight the same contents for future loads of the same page, taking care of all inner elements that the text could have inside.

The idea is simple: simulate when you use a marker inside a book.

Any ideas? Any suggestion will be appreciated.

Thank you in advance.

Isaac

A: 

Use AJAX.

http://www.w3schools.com/Ajax/Default.Asp

IMO, DOM location and the STRING range.

something like,

DOM_LOCATION: div[0]>p[2]>span[1]
STRING_RANGE: 2:20

this means that the string user highlighted from the 2nd character to the 20th character of the 2nd span of the 3rd paragraph of the 1st div, which is "monstration of some" from the example below.

<div>
    <p>This has no use.</p>
    <p><em>And so is</em> this one.</p>
    <p><span>This</span> is the <span>demonstration of something wonderful</span>.</p>
</div>

All you need to do is reverse the DOM location and use the range.

sheeks06
Yes, I know I'll use AJAX to save it to the DB, but, I was wondering about which kind of information should be enough to make future loads of that highlight.
IsaacSF
I've edited my answer above :)
sheeks06
Thank you for being more specific. Do you know if the range values are the same for the main browsers (IE,FF,CH)?I have writed JS code but I found that there are some different characters (TAB, CR, etc.) inside the DOM for each browser, that makes me impossible to trust these range values.
IsaacSF
Yes, specially for IE. and if your doing your html in a non-standard way. IE tries to add missing elements like tbody... tabs, multiple white spaces and CR's are also ignored. I haven't tried if you've written these characters as html entities, though.
sheeks06
If your going to map the dom again, you should set "tolerance" rules.
sheeks06