TINYMCE set focus ... just won't work

I tried

tinyMCE.execInstanceCommand("content", "mceFocus"); 

I tried

 tinyMCE.execCommand('mceFocus', false, "content"); 

None of them work: - (

+4
source share
2 answers

Well, I'm stuck in the same problem. But I believe that it depends on where you are executing the code. Here are some links I have found so far:

http://tinymce.moxiecode.com/forum/viewtopic.php?id=8238

http://tinymce.moxiecode.com/forum/viewtopic.php?pid=91307#p91307


But I solved my problem as follows, and this may not apply to yours:

this.focus();

this.tinymce.execCommand('mceFocus', false, 'yourTinyMCEtextAreaID_goes_here');

This code has been applied inside tiny_mce_src.js -> InsertHorizontalRule so that you can have an idea of ​​the area.


Hope this helps.

+6
source

There is an even simpler way than the previous suggested code. When you initialize tinymce, it is possible to set configuration parameters. Just make sure you set the AUTOFOCUS option.

 var editorOptions = { script_url: "/scripts/tinymce/tiny_mce.js", theme: "advanced", entities: "", theme_advanced_toolbar_location: "top", theme_advanced_toolbar_align: "left", theme_advanced_statusbar_location: "bottom", theme_advanced_resizing: true, content_css: "/styles/site.css", template_external_list_url: "lists/template_list.js", external_link_list_url: "lists/link_list.js", external_image_list_url: "lists/image_list.js", media_external_list_url: "lists/media_list.js", theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,bullist,numlist,|,undo,redo,|,link,unlink,anchor,image,help", theme_advanced_buttons2: "", theme_advanced_buttons3: "", theme_advanced_buttons4: "", width: "640", height: "220", auto_focus: "body2" }; 
+4
source

Source: https://habr.com/ru/post/1343746/


All Articles