admin管理员组文章数量:1308100
When click on edit button it displays tinymce text editor but the problem is it does not set focus on first load of editor from second onward it work fine
Below is what i have tried
HTML
<h3>History Review <a href="#" class="blue_edit_btn" id="history_review_link" onclick="bgshoweditor('history_review')" >Edit</a></h3>
JQuery
function bgshoweditor(editorid)
{
$("#"+editorid+"_div").hide();
$("#"+editorid).show();
tinyMCE.execCommand('mceRemoveControl', false, editorid );
tinyMCE.execCommand('mceAddControl', true, editorid );
tinyMCE.execCommand('mceFocus', false, editorid );
tinyMCE.activeEditor.selection.select(tinyMCE.activeEditor.getBody(), true);
tinyMCE.activeEditor.selection.collapse(false);
}
When click on edit button it displays tinymce text editor but the problem is it does not set focus on first load of editor from second onward it work fine
Below is what i have tried
HTML
<h3>History Review <a href="#" class="blue_edit_btn" id="history_review_link" onclick="bgshoweditor('history_review')" >Edit</a></h3>
JQuery
function bgshoweditor(editorid)
{
$("#"+editorid+"_div").hide();
$("#"+editorid).show();
tinyMCE.execCommand('mceRemoveControl', false, editorid );
tinyMCE.execCommand('mceAddControl', true, editorid );
tinyMCE.execCommand('mceFocus', false, editorid );
tinyMCE.activeEditor.selection.select(tinyMCE.activeEditor.getBody(), true);
tinyMCE.activeEditor.selection.collapse(false);
}
Share
Improve this question
asked May 23, 2014 at 7:25
Nilesh GajareNilesh Gajare
6,3983 gold badges44 silver badges73 bronze badges
1
- for me first time it will occur,but for the other times,it won't work :( – Vaisakh Parannattil Cherul Commented Aug 28, 2014 at 9:40
4 Answers
Reset to default 5Maybe the mceFocus
mand is removed in TinyMce 4
(I said this, because in 4.x removed mceRemoveControl
and mceAddControl
removed).
So, I remend to use the .focus()
try this :
tinyMCE.get(editorid).focus();
Working Example
OR you can use the auto_focus
property.
auto_focus: This option enables you to auto focus an editor instance.
Note: auto_focus set focus on editor when it's load
Try this code may work for you
function bgshoweditor(editorid)
{
$("#"+editorid+"_div").hide();
$("#"+editorid).show();
if (tinyMCE.activeEditor == null || tinyMCE.activeEditor.isHidden() != false) {
tinyMCE.execCommand('mceRemoveControl', false, editorid );
}
tinyMCE.execCommand('mceAddControl', true, editorid );
tinyMCE.execCommand('mceFocus', false, editorid );
tinyMCE.activeEditor.selection.select(tinyMCE.activeEditor.getBody(), true);
tinyMCE.activeEditor.selection.collapse(false);
}
for tinyMCE v4+
tinymce.activeEditor.focus();
Just in case you are looking for a solution for the VUE thin plugin @tinymce/tinymce-vue
import { getTinymce } from '@tinymce/tinymce-vue/lib/es2015/main/ts/TinyMCE'
const tinyMCE = getTinymce()
tinyMCE.activeEditor.focus()
本文标签: javascriptSet focus onload of TinyMce editorStack Overflow
版权声明:本文标题:javascript - Set focus onload of TinyMce editor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741820502a2399335.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论