I am using Ckeditor in drupal 7.26. I placed HTML Content with link tag in the source of Ckeditor. It removes link tag. I want to send my css file through that html content. How can I add it into the editor.
1 Answer
As Clive said there is almost certainly no situation that CKeditor can validly edit/create an html head
element. Since link
must be a child of a head element this means that CKEditor cannot create a valid link
element.
That being said there is a way to add a stylesheet the the CKEditor. You will have to allow JavaScript in whatever filter you are using (so use with caution) and then insert a script like this:
<script>
(function($) {
$('head').apend("<link rel='stylesheet' href='my/added/stylesheet.css'>");
}(jQuery))
</script>
Or if you don't want to use jQuery:
<script>
var element = document.createElement("link");
element.setAttribute("rel", "stylesheet");
element.setAttribute("href", "/my/added/stylesheet.css");
document.getElementsByTagName("head")[0].appendChild(element);
</script>
<link>
tag is only valid inside the<head>
of a document, and I can't think of a situation where you would be using CKEditor to edit the<head>
, even if you could solve this, what use would it be other than to make sure your document is invalid?<head>
section in CKEditor? That's probably the problem. It's not valid to include<head>
inside<body>
. It needs to be a direct descendant of<html>
, which you don't have access to in CKEditor (usually)