0

I've turned a simple text box into one with editing features using the wysihtml5 editor. The project necessitates that the text box inject its html into an iframe. Previous to installing the editor, things were working great. Now, the jQuery for the iframe injection no longer works, since the editor has converted the textarea to an iframe. Any ideas on how I might convert the following jQuery to work with the editor?

    (function() {

    var frame = $('iframe#preview'),
        contents = frame.contents(),
        body = contents.find('body'),
        styleTag = contents
                   .find('head')
                   .append('<style>*{font-family:arial}h2{color:#CC6600}</style>')
                   .children('style');

    $('textarea').focus(function() {
      var $this = $(this);

    $this.keyup(function() {
      body.html( $this.val() );
    });
  });
})();

I know that something needs to change in the $('textarea').focus call, I just don't know what. I'm new to the javascript/jQuery world and have tried a few possibilities, but so far haven't been able to figure this one out.

Many thanks for any insight.

4

1 回答 1

0

据我所知(可能我知道我在说什么),您不能将 css 样式应用于 iframe 之外的 iframe(来自父文档)。您应该尝试在 iframe 中嵌入样式。这是因为浏览器样式适用于文档,但 iframe 是另一个文档,并且必须附带自己的 css 样式。希望这可以帮助

于 2014-08-19T06:43:28.257 回答