How to clear openwysiwyg editor contents?

I am using the openwysiwyg editor on my web page. I want to clear its contents. I used

$('#report').val('');

but it does not clear it.

The editor creates an iframe and updates the content there, synchronizing it.

How can I clean it?

+3
source share
3 answers

You probably need to provide a little more information - html itself would be very useful, but I'm going to assume that reportis the identifier of the text field that you need to clear.

If this is a normal text area, your code really should work.

( ), openwysiwyg, , iFrame HTML-. iFrame.

, .


, , iFrame: http://www.bennadel.com/index.cfm?dax=blog:1592.view


example.html, openwysiwyg:

<script type="text/javascript">
    // Use it to attach the editor to all textareas with full featured setup
    //WYSIWYG.attach('all', full);

    // Use it to attach the editor directly to a defined textarea
    WYSIWYG.attach('textarea1'); // default setup
    WYSIWYG.attach('textarea2', full); // full featured setup
    WYSIWYG.attach('textarea3', small); // small setup

    // Use it to display an iframes instead of a textareas
    //WYSIWYG.display('all', full);  

    function getIFrameDocument( id )
    {
        var iframe = document.getElementById(id);

        if (iframe.contentDocument) {
            // For NS6
            return iframe.contentDocument; 
        } else if (iframe.contentWindow) {
            // For IE5.5 and IE6
            return iframe.contentWindow.document;
        } else if (iframe.document) {
            // For IE5
            return iframe.document;
        } else {
            return null;
        }
    }

    function clearcontents()
    {
        getIFrameDocument('wysiwygtextarea1').body.innerHTML = '';
    }
</script>

- ( div):

<div style="width:120px;height:20px;background:#ff0000;text-align:center;display:block;" onclick="clearcontents();">Clear!</div>

, wysiwyg. iFrame.

Firefox, . iFrame, -, , , :)

+5

, :

var frame = WYSIWYG.getEditor('--ENTER EDITOR NAME HERE--');
var doc = frame.contentWindow.document;
var $body = $('html',doc);
$body.html('');

--ENTER EDITOR NAME HERE-- , attach.

+1

,

$('#report').text('');
0

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


All Articles