Fmdpa Posted November 16, 2011 Share Posted November 16, 2011 I'm using WYMeditor (http://www.wymeditor.org) on a website I'm building. The way the editor works is by inserting an iframe into the page. Unfortunately, that means that there are no styles applied to the content of the iframe. Consequently, I want to insert a stylesheet into the iframe to make it look like what it will when the edit is saved. Here's how I went about it: $('#edit').wymeditor() // initialize wymeditor // add styles to iframe var iframe = $('iframe').first(),style = document.createElement('link') style.type = 'text/css'style.rel = 'stylesheet'style.href = '/styles/styles.css' iframe.contentWindow.document.body.appendChild(style) This works when I enter the "add styles to iframe" section from the console. But when I put them into a script on the page, it doesn't work anymore. I did some debugging to see why, and it is because the iframe is not loaded yet ("undefined"). If I run the function 1 second after the WYMeditor is initialized, then it adds the stylesheet successfully. But there must be a better solution than that, though. Any ideas? Link to comment Share on other sites More sharing options...
dsonesuk Posted November 16, 2011 Share Posted November 16, 2011 Just a quick look at their forum, and came across this http://community.wymeditor.org/discussion/26/a-sites-css-used-in-preview Link to comment Share on other sites More sharing options...
Fmdpa Posted November 18, 2011 Author Share Posted November 18, 2011 Thanks, that link helped and I think I'll be able to figure it out. Sometimes working with third-party code drives me nuts. Other than very simple, well-documented APIs, this reminded me how much I really dislike working with third-party code. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.