How To Preserve Text Selection When Opening A Jquery Dialog
Using jQuery's dialog I came across the following quirk (tested in FF3): User selects text In code, open up a jQuery dialog BUG: the text gets unselected (text could be in a text
Solution 1:
The jQuery dialog will take the user's focus ( you should see one of the buttons selected on the dialog ). Browsers only have 1 focus so you lose whatever they had selected.
You should just retrieve the start and end positions of the user's selection before you do the dialog, and then reselected it after the dialog goes away.
I don't have any example code for getting and setting user's selection, but a web search should find you some.
Something like :
$("dialog").focus(function() {
// save the selection
}).blur(function() {
// set the text selection
});
[edited (Nickolay): see Keep text selection when focus changes for more code]
Post a Comment for "How To Preserve Text Selection When Opening A Jquery Dialog"