3

I have integrated CKEditor into my website CMS. The Preview button works but I cannot get it to use stylesheets (CSS). I have edited the preview.html located in:

Website/ckeditor/plugins/preview/

But it doesn't seem to listen to any of the html I wrap around the code that pulls the content from the WYSIWYG editor.

As I understand this bit of code:

<script>

var doc = document;
doc.open();
doc.write( window.opener._cke_htmlToLoad );
doc.close();

delete window.opener._cke_htmlToLoad;

</script>

Pulls in whatever is in the editor, so I should be able to wrap around that html to include elements that will be available for every page? And links to stylesheets?

Anyone ever done this? Is it possible?

1 Answer 1

0

The "window.opener._cke_htmlToLoad" seems to be a string (containing a complete html document).

To get the innerHtml of the <body></body>, you can use this regex:

var doc = window.opener._cke_htmlToLoad; // is string
var innerBody = ( doc.replace(/((?:.(?!<\s*body[^>]*>))+.<\s*body[^>]*>)|(<\s*\/\s*body\s*\>.+)/g,'') );
document.getElementById('insertIntoMe').innerHTML = innerBody;

From my testing this seems only to work in Firefox. But Chrome and Internet Explorer directly display the window document without allowing any changes. So maybe somebody else can provide a better solution?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.