Days
Hours
Minutes
Seconds
x

New Froala Editor v5.0.0 is here โ€“ Learn More

Skip to content
Froala Documentation

API

Save / Restore Selection

Try it yourself:


Edit in JSFiddle

HTML

<div id="froala-editor">
  <ol>
    <li>You can use the buttons to play around with the selection:
      <ul>
        <li>The first button saves the selection.</li>
        <li>The second button restores the selection.</li>
        <li>The last button clears the selection.</li>
      </ul>
    </li>
    <li>The selection will be restored correctly only if you don't make any changes by typing into the WYSIWYG HTML editor after you save it.</li>
  </ol>
</div>

JAVASCRIPT

<script>
  $(function() {
    FroalaEditor.DefineIcon('saveSelection', {NAME: 'download', SVG_KEY: 'star'});
    FroalaEditor.RegisterCommand('saveSelection', {
      title: 'Info',
      focus: true,
      undo: false,
      refreshAfterCallback: false,
      callback: function () {
        this.selection.save();
        alert('selection saved');
      }
    });

    FroalaEditor.DefineIcon('restoreSelection', {NAME: 'upload', 'SVG_KEY': 'add'});
    FroalaEditor.RegisterCommand('restoreSelection', {
      title: 'Info',
      focus: true,
      undo: false,
      refreshAfterCallback: false,
      callback: function () {
        this.selection.restore();
      }
    });

    FroalaEditor.DefineIcon('clearSelection', {NAME: 'trash'});
    FroalaEditor.RegisterCommand('clearSelection', {
      title: 'Info',
      focus: true,
      undo: false,
      refreshAfterCallback: false,
      callback: function () {
        this.selection.clear();
      }
    });

    new FroalaEditor('div#froala-editor', {
      toolbarButtons: [
        'saveSelection', 'restoreSelection', 'clearSelection'
      ]
    })
  });
</script>
Sign up

Download the code by signing up for our newsletter

Sign up

Download the code by signing up for our newsletter

Note: By registering, you confirm that you agree to the processing of your personal data by Froala, Inc. - Froala as described in the Privacy Statement. Froala, Inc. - Froala is part of the Idera group and may share your information with its parent company Idera, Inc., and its affiliates. For further details on how your data is used, stored, and shared, please review our Privacy Statement.