<html lang="en">
<head>
<title>Internet Explorer and the Undo Buffer</title>
<style type="text/css">
body {
font-family: sans-serif;
}
</style>
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript">
YAHOO.util.Event.onDOMReady(function() {
var Dom = YAHOO.util.Dom;
var Event = YAHOO.util.Event;
Event.on('el-b', 'keypress', function(e) {
var el = document.createElement('p');
document.body.appendChild(el);
document.body.removeChild(el);
});
var colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];
Event.on('el-c', 'keypress', function(e) {
var index = Math.floor(Math.random() * colors.length);
Dom.setStyle(Event.getTarget(e), 'color', colors[index]);
});
});
</script>
</head>
<body>
<table>
<tbody>
<tr>
<td>A</td>
<td>
<textarea id="el-a" cols="40" rows="6"></textarea>
</td>
</tr>
<tr>
<td>B</td>
<td>
<textarea id="el-b" cols="40" rows="6"></textarea>
</td>
</tr>
<tr>
<td>C</td>
<td>
<textarea id="el-c" cols="40" rows="6"></textarea>
</td>
</tr>
</tbody>
</table>
<p>
This page demonstrates the effect of changing the DOM on Internet Explorer's undo buffer. This error does not seem to be well documented, <a href="http://www.codeproject.com/KB/scripting/htmlarea.aspx#bugs1">the only mention I could find of the issue</a> was documented as part of Fraser Cain's htmlArea control.
</p>
<p>
You need to view this page with Internet Explorer (6 - 8) to observe the error.
</p>
<p>
<strong>A</strong> is a standard textarea control. This control demonstrates how the undo buffer normally behaves.
</p>
<p>
<strong>B</strong> has a keypress listener that adds, then removes, an element from the DOM. This demonstrates IE's undo buffer resetting.
</p>
<p>
<strong>C</strong> also has a keypress listener, but in this case the listener only changes the colour of the text in the element. This demonstrates that only certain operations reset the undo buffer.
</p>
<p>
With each of the textareas above try entering some text then invoking undo. <strong>A</strong> and <strong>C</strong> should behave identically, <strong>B</strong> should behave in a non-standard way.
</p>
</body>
</html>
body {
background:orange;
}
Output
300px
This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account
Dismiss xKeyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |