Trigger post Autosave in WYSIWYG Editor or Insert Text into WYSIWYG and Title fields with JS

by Jonathan   Last Updated January 09, 2018 20:08 PM

I need to trigger the Wordpress Autosave feature automatically within 1-2 seconds of a new post screen coming up. The two ways I can think of doing this would be a direct JS call or by simulating adding content to the fields to trigger the listener script.

Apparently there used to a way to directly call the autosave, but it was deprecated.

window.autosave = function(){};

Is there a newer way to achieve this?

I set about trying to insert content into the WYSIWYG editor using JS, but for some reason the target returns null.

var para = document.createElement("P");                       // Create a <p> node
var t = document.createTextNode("This is a paragraph.");      // Create a text node
para.appendChild(t);                                          // Append the text to <p>
document.getElementById("tinymce").appendChild(para);    

I tried this targeting the body tag with id "tinymce"

and also targeting the subject field ID "inner-editor"

Targeting elsewhere works, but these attempts return "Uncaught TypeError: Cannot read property 'appendChild' of null"

Any ideas would be welcome - I just need to get this autosave automatically firing within a couple seconds of the new post screen loading!

Tags : wysiwyg autosave


Related Questions


Autosave setting stays in default value

Updated July 14, 2015 14:03 PM

Trigger save as draft when uploaded image

Updated March 13, 2017 06:08 AM

Saving of Draft is failing

Updated August 13, 2018 20:08 PM

Autosave control in WordPress

Updated February 24, 2017 18:08 PM

Enabling autosave when plugin disabled

Updated February 25, 2017 16:08 PM