Append a stylesheet to an iframe with jQuery

前端 未结 5 805
情书的邮戳
情书的邮戳 2020-11-30 05:35

I\'m creating an HTML editor, similar to this one I\'m typing in right now with the output below. I\'m using an iframe and dumping the $htmlTextBox.val() into the body of th

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 05:53

    Whilst you can interact with an iframe's document.styleSheets, the old-school reliable way is either to have the stylesheet there in the first place (by writing an iframe-src to point to an empty document with the desired stylesheet), or put it in place with document.write(). For example:

    
        
        
    
    

    (This will also set the iframe document to Standards Mode, assuming that's what you want.)

提交回复
热议问题