Rectangle 27 0

javascript How to preserve text selection when opening a jQuery dialog?


$("dialog").focus(function() {
  // save the selection
}).blur(function() {
  // set the text selection
});

I don't have any example code for getting and setting user's selection, but a web search should find you some.

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.

Note
Rectangle 27 0

javascript How to preserve text selection when opening a jQuery dialog?


$("dialog").focus(function() {
  // save the selection
}).blur(function() {
  // set the text selection
});

I don't have any example code for getting and setting user's selection, but a web search should find you some.

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.

Note