'tinymce dont show the alert leaving the page

I am using jquery with normal version 3.4.3.2 (non-jquery). I am using jquery to get contents of the box like this

    $(function(){
        $(".submit").click(function() {
            var text = tinyMCE.get('elm1').getContent();
            $(".here").html(text);
            return false;
        });
    });

But when i edit the content of the textarea and click submit and then leave the page. But it shows the alert box. I dont want it to come if the users have clicked the .submit after editing. Thanks



Solution 1:[1]

Brett seems right.

You can even use this to get the content into the form in case $(."here") ist the element you initialized the tinymce editor for:

    $(".submit").click(function() {
        tinymce.get('elm1').save();
        return false;
    });

Solution 2:[2]

Sorry to post in an old topic but I tried .save() and it did not work for me either. So, I figured out a better solution that I wanted to share for the next person.

The unsaved alert is part of the autosave plugin which checks function tinymce.get('mce1').isDirty(). This function checks the value of tinymce.get('mce1').isNotDirty

A "dirty" mce is one which has unsaved changes. So, to prevent the popup you have to tell mce that it is clean without any unsaved changes.

tinymce.get('mce1').isNotDirty = 1;//clean mce

That will prevent the popup when leaving/refreshing page, assuming no more edits are done to the content of mce1

Solution 3:[3]

If you have one editor per page try

tinymce.activeEditor.save();

See the documentation for more details https://www.tiny.cloud/docs/api/tinymce/tinymce.editor/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Thariama
Solution 2 JAX
Solution 3 Ruslan Muraha