0

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.

6
  • Considering the <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?
    – Clive
    Jan 5 '15 at 14:18
  • Yeah, I Placed link tag in <head> section but it removes Head tags along with <link> tag
    – Manu
    Jan 5 '15 at 14:24
  • So you're adding a <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)
    – Clive
    Jan 5 '15 at 14:25
  • Without head tag also it removes <link> tag
    – Manu
    Jan 5 '15 at 14:43
  • I think it does not accept <link> tag in <body>
    – Manu
    Jan 5 '15 at 14:49
2

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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