Editors and iframes
jasonchen.me
jasonchen.me
However, what the author did not mention was security. My assumption as to why the company that uses my code, still uses it inside an iframe, is to prevent accidental XSS injection from when their user's copy and paste content (sometimes with javascript embedded in it) into the editor. So be careful about that.
Another recommendation I have, is to NOT use execCommand.
Thanks for your article, I really enjoyed it. Matt (http://www.matthewbordenweb.com/)
I would love to hear your plans to overcome this as it is pretty much a hard requirement for any editor integration.
I have run into this and was quite hopeful about <style scoped> but browser support leaves much to be desired.
Years since I've really dabbled in WYSIWYG editing JS, but the best I can think of us to use a reset CSS file namespaced for the `div` (or whatever container) in question.
The Scoped Polyfill https://github.com/PM5544/scoped-polyfill does just this and gets you most of the way there.
> It does so by prepending the styleRules selectorText with id's
Now, on a new product we are developing, We are taking the opposite approach. For TouchStream (https://touchstreamapp.com), we needed a rich text editor for users to edit their emails. We went with Redactor (http://imperavi.com/redactor/) for the editor. However, Redactor is a contenteditable editor, so it was inheriting a bunch of styles from our interface. Not exactly what you want when editing emails. In this case, I used a modified version of Cleanslate (http://cleanslatecss.com/) to reset all of the elements within the contenteditable to their browser defaults. It's not perfect, but I got it pretty close. It's the best you can probably do until scoped styles become more prevalent.
Edit: to be fair, Cleanslate is more of a polyfill for a combo of the css keywords "initial" and "unset".
I do not envy rich text editor authors one bit. Even implementing them has an unreasonable amount of gotcha's when you dive into getting your page and the iframe/editor to communicate effectively.
Recommendation for a simple text editor that doesn't get in the user's way?
> A rich text editor framework for the web platform, with patches for browser inconsistencies and sensible defaults.