Remember the good old days of the browser wars? Phony user-agent detection, documents that sprouted alls and layerses and what have you? You can relive the magic by trying to muck around with IFrames.
In a previous issue, we discussed how to use an IFrame to allow pasting rich text. And, if you have an area that the user consciously selects and pastes to and then proceeds via some other user interaction, then that'll work fine. If, however, you want to attach an event handler onto the IFrame itself so the pasting logic is triggered automagically -- well, then, you're in for a world of things not working in IE.
var pasteIframe = $('pasteIframe').contentDocument || $('pasteIframe').contentWindow.document;
pasteIframe.designMode = 'on';
This is as before.
pasteArea = pasteIframe.body;
if (!pasteArea) {
pasteIframe.write('<body></body>');
pasteArea = pasteIframe.body;
}
Event.observe(pasteArea ....
And, yes, the HTML contents of our IFrame were perfectly valid XHTML1.1 and had a body tag and everything.
Update: why write the "body" tag conditionally, and not just do it every time? Well, Firefox will "spin" indefinitely and never complete loading if you try that. And now we know.
It's the beauty of writing cross-browser Javascript. Some days, you program, using code. Some days, you chant invocations and burn chicken feet. Today was a bad day for poultry.
Recent Comments