我正在开发一个小的Wordpress插件,它使用JavaScript将带有css类的html标记添加到Wordpress编辑器的可视文本视图中。我使用经典编辑器。
根据Chrome开发工具,可视文本编辑器由几个div元素组成,然后是一个id为;内容\\u ifr“;它加载第二个body元素,该元素包含与帖子相关的所有html标记:
<body id="tinymce" class="mce-content-body content post-type-post post-status-publish post-format-standard page-template-default locale-de-de mceContentBody wp-editor wp-autoresize html5-captions" data-id="content" dir="ltr" style="overflow-y: hidden;" contenteditable="true"><p>Post content</p></body>
我已经发现我可以使用document.getElementById("content_ifr").contentDocument.body
但这只适用于控制台中的手动输入,在加载所有内容之后。它在插件的JavaScript文件中不起作用,该插件的php文件通过wp\\u enqueue\\u脚本加载该插件。相应的变量始终返回null。如何使经典编辑器的内容可供插件的JavaScript文件访问?