I have a normal textbox, and a lightbox with a text input.
I want to keep the user's selection in the textbox, even when the user focuses on the lightbox's text input.
- Select text in normal textbox
- Toggle lightbox
- Focus on lightbox input
At step 3., the user's text selection is discarded. How can this be prevented? See Google docs link insertion lightbox for example.
Thanks :)
Update
Ok, so Google docs uses an iframe for the blank page section, which is how they are handling the multiple selections. Something like this (excuse the disgusting HTML):
// test.html
<html><body>
<h1 onclick='lightbox();'>This is the main section</h1>
<iframe src='frame.html'></iframe>
<div id='lightbox' style='display: none; position: fixed; top: 0; left: 0; height: 100%; width: 100%; opacity: 0.8; background-color: black;'>
<input type='text' name='url' />
</div>
<script type='text/javascript'>
function lightbox() {
document.getElementById('lightbox').style.display = 'block';
}
</script>
</body></html>
// frame.html
<p>This is my iframe</p>
Text selection in the iframe is independent of focus on the input in the lightbox. So if some of the text 'This is my iframe' is selected, then the lightbox is toggled and the cursor placed in the input, the iframe's text selection persists without any javascript.
I'm trying Nickolay's suggestion now.