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 7919497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:53:08+00:00 2026-06-03T15:53:08+00:00

I am running this piece of code, for de-selecting a word a user selected

  • 0

I am running this piece of code, for de-selecting a word a user selected in an iframe, when he selects another word outside the iframe:

function getCurrentWord() {
    var range;
    var w = "";

    if (document.selection) {
        ////IE
        range = document.selection.createRange();
        w = trim(range.text);
    } else {
        ////NOTIE
        w = trim(window.getSelection().toString());
    }

    if (w != "" && document.getElementById("frmBook")) {
        var oTextRange;
        if (document.selection) {
            ////IE
            oTextRange = document.getElementById("frmBook").contentWindow.document.selection.createRange();
            oTextRange.expand("word");
            oTextRange.execCommand("unselect") ;
        } else {
            ////NOTIE       
            oTextRange = document.getElementById("frmBook").contentWindow.getSelection();
            oTextRange.collapseToStart();
        }
    }

    if (w == "" && document.getElementById("frmBook")) {
        if (document.selection) {
            ////IE
            range = document.getElementById("frmBook").contentWindow.document.selection.createRange();
            w = trim(range.text);
        } else {
            ////NOTIE
            w = trim(document.getElementById("frmBook").contentWindow.getSelection().toString());
            /*
            IF I PUT IT HERE IT DOESN'T SHOW AN ERROR
            oTextRange = document.getElementById("frmBook").contentWindow.getSelection();
            oTextRange.collapseToStart();
            */
        }
    }
    return w;
}

The problem is i get this error on firefox error console:

Timestamp: 9/5/2012 12:20:42 μμ
Error: uncaught exception: [Exception… “An attempt was made to use an object that is not, or is no longer, usable” code: “11” nsresult: “0x8053000b (NS_ERROR_DOM_INVALID_STATE_ERR)” location: “http://192.168.0.88/test.js Line: 295″]

and that error occurs when the code is at the

oTextRange.collapseToStart();

line.

I tried to run it in a single line like this :

document.getElementById("frmBook").contentWindow.getSelection().collapseToStart();

but i get the same error

frmBook is the ID of the iframe

IF i run that piece of code which causes the error where I have commented it out, it doesn’t show an error and that’s weird!

Anybody knows what am I doing wrong ?
Thanks in advance

  • 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-03T15:53:10+00:00Added an answer on June 3, 2026 at 3:53 pm

    Looking at (what may possibly be an old version of) the source code at http://dxr.lanedo.com/mozilla-central/layout/generic/nsSelection.cpp.html it seems that collapseToStart will produce that error if nothing is actually selected. You could check whether oTextRange.rangeCount is < 1, and simply not do the collapse if so. (If there’s some reason why that should be impossible, then you probably have a different problem.)

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

Sidebar

Related Questions

Running the static analyzer on this piece of code: - (id) readForeignPref { CFPropertyListRef
I have problem running and debugging this piece of code: bool readSectionHeaders(char* path, int
I'm running this piece of code: $sql = SELECT IF(TIMEDIFF(NOW(),last_update) > '02:00:00',1,0) AS morethan
I tried running this piece of code: path = '/bla/bla/bla' if path is True:
Currently learning Scheme/Racket and have problem running this piece of code. (if (or (<
Running this piece of code will print null public class Weird { static class
I'm running AQTime on this piece of code, I found that .IndexOf takes 16%
I'm running this code on my datasheet subform when my form loads and I'm
I'm running this C# code in Visual Studio in debug mode: public class MyHandlerFactory
I'd like to optimize this piece of code : public void PopulatePixelValueMatrices(GenericImage image,int Width,

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.