javascript - Keep text selection when focus changes -


I have a generic textbox, and there is a lightbox with a text input.

I select the user in the text box, even if the user is focused on the text input of the lightbox.

  • Select the text in the normal text box
  • Toggle lightbox
  • Turn focus on Lightbox input
  • Step 3 However, the text of the user is discarded. How can this be prevented? For example see the Google Docs link entry lightbox.

    Update

    OK, so Google uses an iframe for Docs blank page segment, Anything that they are handling (like the excuse of hateful HTML):

      // test.html & lt; Html & gt; & Lt; Body & gt; & Lt; H1 onclic = 'lightbox ();' & Gt; This is the main part & lt; / H1> & Lt; Iframe src = 'frame.html' & gt; & Lt; / Iframe & gt; & Lt; Div id = 'lightbox' style = 'display: none; Status: fixed; Top: 0; Left: 0; Height: 100%; Width: 100%; Opacity: 0.8; Background color: black; '& Gt; & Lt; Input type = 'text' name = 'url' / & gt; & Lt; / Div & gt; & Lt; Script type = 'text / javascript' & gt; Function lightbox () {document.getElementById ('lightbox'). Style.display = 'block'; } & Lt; / Script & gt; & Lt; / Body & gt; & Lt; / Html & gt; // frame.html & lt; P & gt; This is my iframe & lt; / P & gt;  

    The focus in the input in the lightbox is if the text selection in the iframe is free so if some text is selected 'This is my iframe' then the lightbox is toggled and The cursor placed in the input, the iframe's text selection remains intact without any javascript.

    I'm trying to suggest Nicolai

    From: You have to preserve the selection and restore it to focus. Must do:

      $ ("dialog"). Focus (function () {// save selection}}. Blur (function () {// set text selection});  

    Selecting Selection (From):

      $ Fn.selectRange = function (start, end) {return.Each (function () {if (This.SetSelectionRange) {this.focus (); this.setSelectionRange (start, end);} and if (this.createTextRange) { Var range = this.createTextRange (); range.collapse (true); range.moveEnd ('character', end); category.movest ('character', start); category.select ();}}); }; $ ('# ELEM') selectRange (3,5).  

    Getting the Selection:


    Comments

    Popular posts from this blog

    MySql variables and php -

    url rewriting - How to implement the returnurl like SO in PHP? -

    Which Python client library should I use for CouchdB? -