D
Dekortage
Hi all...
I am able to grab the text that a user has selected on a web page,
using this code:
function moreInfo() {
if (!isIE) {
var t = window.getSelection();
// act on variable "t";
} else if (document.selection && document.selection.createRange) {
var t = document.selection.createRange();
if (document.selection.type == 'Text' && t.text>'') {
document.selection.empty();
// act on variable "t";
}
}
}
(the boolean "isIE" is established earlier in the code)
This works. However, I'm wondering how to get the words *around* the
selected word. Take these sentences for example: "If you need to
framglubble the zartbox, then you should buy the red widget.
Otherwise you can buy the blue widget and save some money."
My code will tell me if the person has selected the word "widget".
But I'd like to know if the selection is after "red" or "blue". Is
this possible? I've been scouring the Internet for some advice, and
I'm having trouble finding an answer.
Many thanks in advance for your time.
I am able to grab the text that a user has selected on a web page,
using this code:
function moreInfo() {
if (!isIE) {
var t = window.getSelection();
// act on variable "t";
} else if (document.selection && document.selection.createRange) {
var t = document.selection.createRange();
if (document.selection.type == 'Text' && t.text>'') {
document.selection.empty();
// act on variable "t";
}
}
}
(the boolean "isIE" is established earlier in the code)
This works. However, I'm wondering how to get the words *around* the
selected word. Take these sentences for example: "If you need to
framglubble the zartbox, then you should buy the red widget.
Otherwise you can buy the blue widget and save some money."
My code will tell me if the person has selected the word "widget".
But I'd like to know if the selection is after "red" or "blue". Is
this possible? I've been scouring the Internet for some advice, and
I'm having trouble finding an answer.
Many thanks in advance for your time.