Add CSS to iframe elements using the .css - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:IFrame


Add CSS to iframe elements using the .css

Demo Code

ResultView the demo in separate window

<html lang="en">
   <body translate="no"> 
      <div class="text-editor"> 
         <iframe class="text-field" id="text-field" src="about:blank" contenteditable="true"> </iframe> 
      window.onload = function() {
  var frameElement = document.getElementById("text-field");
  var doc = frameElement.contentDocument;
  doc.body.contentEditable = true;
  doc.body.innerHTML = doc.body.innerHTML + '<style>body {color:red;}</style>'
    // ww w .  ja v a2  s  .  c o  m

Related Tutorials