Docs › Saving and output
Read-only
Show content that cannot be edited with readOnly and setReadOnly.
For approved documents, closed posts, or viewers without edit rights: the content looks the same as in the editor but cannot be changed. Start with readOnly: true or switch with editor.setReadOnly(true).
Try it
Meeting notes
- Fix the schedule
- Review the budget
Attendees (click to open)
Minji, Seojun, Haeun
Code for this demo
createEditor('#editor', {
toolbar: 'heading | bold italic | link | preview fullscreen',
readOnly: true,
onReady: (ed) => {
const btn = document.createElement('button');
btn.type = 'button';
btn.textContent = 'Edit';
btn.onclick = () => {
ed.setReadOnly(!ed.readOnly);
btn.textContent = ed.readOnly ? 'Edit' : 'Make read-only';
};
ed.statusEl.prepend(btn);
},
});What changes
- No typing or pasting, and no caret.
- Most toolbar buttons are disabled. These stay on:
findReplace,preview,print,fullscreen,help. - Checklist boxes do not toggle, and clicking images, tables or boxes does not bring up their bars.
- Folded sections (Details) show folded as saved, and readers can open them. Back in edit mode they open up again.
- The editor gets the
is-readonlyclass for your CSS.
const editor = createEditor('#editor', { readOnly: !canEdit });
editButton.addEventListener('click', () => editor.setReadOnly(false));
console.log(editor.readOnly); // current stateFor a plain view page, putting the saved HTML into the page is lighter than loading an editor.
Options
| Name | Type | Default | Description |
|---|---|---|---|
readOnly | boolean | false | Start read-only |
setReadOnly(ro) | method | - | Turn read-only on or off |
readOnly | property | - | Whether it is read-only now |