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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:39:28+00:00 2026-05-29T07:39:28+00:00

I am making a little word prediction plugin for tinyMCE and need to extract

  • 0

I am making a little word prediction plugin for tinyMCE and need to extract a bit of text and later insert text from a list of predicted words. The insertion should be no problem, as I know where the cursor is and can use the mceInsertContent command. Getting the text for the prediction however…

I need to extract a subset of the text ending at the letter immediately before the cursor position and starting at, well, the start of the text. I can strip HTML tags myself if neccessary, but I prefer letting tinyMCE do it if possible.

I was thinking of doing it like this:

  1. Insert bookmark at current cursor positon using mceInsertContent
  2. Create a range from start of text up to my bookmark.
  3. Get the content of the range.
  4. Delete the bookmark.

Now, since I’m not that well versed in tinyMCE that has proved to be a bit of a challenge for me, so how would one go about doing this?

The code needs to work cross-browser.

  • 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-05-29T07:39:30+00:00Added an answer on May 29, 2026 at 7:39 am

    You may try this code snippets (ed is the tinymce editor object)

    A. Insert bookmark at current cursor positon using mceInsertContent

    ed.execCommand('mceInsertContent', false,'<span class="marker">\ufeff</span>');
    

    B. Create a range from start of text up to my bookmark.

    var rng = ed.selection.getRng(1);
    var rng2 = rng.cloneRange();
    
    // set start of range to begin of forst paragraph
    rng2.setStartBefore($(ed.getBody()).find('p:first').get(0));
    
    rng2.setEndBefore($(ed.getBody()).find('span.marker').get(0));
    ed.selection.setRng(rng2);
    

    C. Get the content of the range.

    // get content of selection (range)
    var content = ed.selection.getContent({format: 'text'});
    

    D. Delete the bookmark.

    $(ed.getBody()).find('span.marker').remove();
    

    Update: If you are concerned about the selection change you may reset your initial range

    ed.selection.setRng(rng);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a little vocabulary-quiz app, and the basic model for a word is
I'm making a little message sending module. It'll handle queuing messages from a request
I'm having a little bit of trouble making a sticky form that will remember
I'm making a little web based game and need to determine where to put
I am currently toying around with android and making a little bit of a
I'm making a little voting tool (voting from 1 to 5) and I have
Hello guys i'm making a little app in which i need to enumerate all
Im making a little shopping list app. In the app, if an item in
I'm making a little jQuery plugin that creates a slider for images and content.
I am making a little program thath will read data from website. String in

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.