mscha
mscha

Reputation: 6830

Can I prevent TinyMCE setContent from stealing focus?

When I use setContent on a TinyMCE editor, it sets the focus to that editor control.

var te = tinymce.get('my_id');
te.setContent('new contents');

Any way to prevent this?

Upvotes: 3

Views: 1681

Answers (2)

Esailija
Esailija

Reputation: 140210

Looking at the source code (I haven't used tinymce), I cannot find anything that would set the focus but there are some events that are fired so I think this is worth giving a shot:

te.setContent( 'new contents', { no_events: true } );

Upvotes: 6

mscha
mscha

Reputation: 6830

My current workaround:

  • set the focus back to the button that was just clicked
  • restore the scrollTop

Using jQuery:

var scrollTop = $(document).scrollTop();

// setContent stuff...

$(this).focus();
$(document).scrollTop(scrollTop);

Upvotes: 1

Related Questions