GeezerVison is showing en.wikibooks.org — JavaScript/Design Mode - Wikibooks, open books for an open world
Design Mode in JavaScript is a hidden and powerful feature of the browser's document object that allows you to make any webpage directly editable in real-time. When enabled, it essentially turns the entire webpage into a live text editor where you can click on elements (like text or images) and modify them directly.
Here’s how you can use and experiment with document.designMode:
Turn on JavaScript remove mode delete all
Steps to Try It in Your Browser Console
- Open any website in your browser.
- Right-click on the page and select Inspect (or press
Ctrl+Shift+I / Cmd+Shift+I).
- Go to the Console tab.
- Type the following command and press Enter:
- Click anywhere on the webpage and start editing the text!
What You Can Do in Design Mode
- Edit Text:
- Click on any text and type directly to edit it.
- Remove Content:
- Highlight text or elements and press
Backspace or Delete to remove them.
- Add Content:
- Place your cursor in a text container and start typing.
- Style Elements:
- Though you can’t directly apply styles through Design Mode, you can combine it with
document.execCommand() to add bold, italics, etc.
A More Interactive Example
You can create a button to toggle Design Mode on and off:
Save this as an .html file and open it in a browser. Click the button to toggle Design Mode!
Notes and Limitations
- Temporary Changes:
- Changes made using Design Mode are not saved permanently. If you reload the page, your edits will disappear.
- Not All Elements Are Editable:
- Some elements like
<button> or custom components might not behave as expected.
- Browsers May Vary:
- Most modern browsers support Design Mode, but behavior might differ slightly.