Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8206493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:41:29+00:00 2026-06-07T08:41:29+00:00

I try to backup a TextRange object in JavaScript to restore it later, so

  • 0

I try to backup a TextRange object in JavaScript to restore it later, so to do this i’ve tried to link a function to the blur event but when the function is called my selection is already lost :/ How can i run specific behaviour BEFORE the blur event ? Or have you an other solution to do this trick ?

I’ve tried this :

this._editableFrame._elt.onload= function(oEvent){
    oEvent.srcElement.contentDocument.body.onblur=function(oEvent) {
    this._sel=this.document.selection.createRange().duplicate(); } 
    /*alert(this._sel.text);*/
    return true; 
};

And when i do this i just have an empty TextRange :/ but if i write an “alert” in the function i succeed to get my text selection in the blur function :/ How can i capture the blur event and what can i do with this type of manipulations ? I’m a beginner in javascript.

Thanks a lot, i spent a lot of time on this problem… :/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:41:30+00:00Added an answer on June 7, 2026 at 8:41 am

    I think blur event is not perfect, this may help you

    var selectedText = "";
    function getSelectedText()
    {
        if (typeof window.getSelection != "undefined") {
            selectedText = window.getSelection().toString();
        }
        else if (typeof document.selection != "undefined" && document.selection.type == "Text")
        {
            selectedText = document.selection.createRange().text;
        }
    }
    
    function show_selected_text()
    {
         getSelectedText();
        if(selectedText) alert(selectedText);
    }
    
    document.onmouseup = show_selected_text;
    document.onkeyup = show_selected_text;
    

    DEMO.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I try to restore a SQL Server 2008 r2 backup I got this
So when I try this code (one line at a time): BACKUP DATABASE [test]
When I try to restore a backup from sqlserver 2008 R2 to sqlserver 2008,
i am using the following code snippet to backup/restore database Backup works fine but
Hello everyone i am try to create backup in postgres through dump. when i
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]
try: recursive_function() except RuntimeError e: # is this a max. recursion depth exceeded exception?
Try executing the following in JavaScript: parseInt('01'); //equals 1 parseInt('02'); //equals 2 parseInt('03'); //equals
I am using the following code snippet to copy/backup database Public Sub backupData() Try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.