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

  • Home
  • SEARCH
  • 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 8269331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:11:24+00:00 2026-06-08T06:11:24+00:00

I’m using a fantastic jquery text editor named Redactor . I’m trying to add

  • 0

I’m using a fantastic jquery text editor named Redactor. I’m trying to add a new button which when clicked gets the text that was highlighted in the text editor.

The script allows to add a new button by adding the following setting:

buttonsCustom: {
        button1: {
            title: 'Button', 
            callback: testButton //executes callback on button click
        } 
}  

then in the callback I want to get the highlighted text

function testButton(obj, event, key)
{
     alert(highlighted_text);
}

I thoroughly looked in the documentation and there’s no way to get highlighted text. I tried other functions like…

function getSelText() {
  var txt = '';
  if (window.getSelection) {
    txt = window.getSelection();
  } else if (document.getSelection) {
    txt = document.getSelection();
  } else if (document.selection) {
    txt = document.selection.createRange().text;
  } else return;
  return txt;
}

…but the text editor script already has a way to do it and would be best to use that.

In the script I found where the text selection function is on line 1719 but can’t figure out how to use it for a custom button.

Anyone experienced with Redactor, please help!

  • 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-08T06:11:26+00:00Added an answer on June 8, 2026 at 6:11 am

    Pick your poison (both methods work on Firefox and IE):

    Method 1: Undocumented internal function

    There is an internal function named getSelection, but it isn’t part of the public API.

    You can call it with $('#redactor_content').data('redactor').getSelection().

    Method 2: Duplicating functionality

    Now if you don’t want to rely on accessing the internals of Redactor, you can duplicate the implementation into your own function, replacing access to internal variables with a call to getDoc():

    function getRedactorSelection(elem)
    {
        var doc = elem.getDoc().get(0);
        if (doc.getSelection)
        {
            return doc.getSelection();
        }
        else if (doc.selection)
        {
            return doc.selection.createRange();
        }
    };
    

    Usage: getRedactorSelection($('#redactor_content'))

    The upside is that you are protected from changes in how internal functions of Redactor are named and called, but the downside is that your code is no longer browser-independent.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the
I have a text area in my form which accepts all possible characters from
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.