无法在iframe头中创建STYLE标记 [英] Cant Create STYLE tag in iframe head

查看:142
本文介绍了无法在iframe头中创建STYLE标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是jsfiddle - > http://jsfiddle.net/uTy5j/7/embedded/结果/

Here's jsfiddle --> http://jsfiddle.net/uTy5j/7/embedded/result/

我正在使用CodeMirror,似乎Codemirror正在删除我创建的样式标记:

I'm using CodeMirror and it seems that Codemirror is erasing my style tag that I create with:

var preview = document.getElementById('preview');
var mypreview = preview.contentDocument;
mypreview.open();
mypreview.close();

var style = document.createElement('style');
style.id = 'mycssid';
style.type ='text/css';
mypreview.head.appendChild(style);

任何人都可以知道如何在所有内容之后将此样式标记附加到iframe的头部已加载?

Can anyone figure out how I can get this style tag appended to the head of the iframe after everything is loaded?

jsFiddle在外部资源中加载了所有codemirror脚本和样式。

The jsFiddle has all codemirror scripts and styles loaded in the external resources.

这是jsfiddle - > http://jsfiddle.net/uTy5j/7/embedded/result/

Here's jsfiddle --> http://jsfiddle.net/uTy5j/7/embedded/result/

推荐答案

在尝试插入内容之前,您必须等到iframe加载:

You just have to wait until the iframe is loaded before you try to insert stuff:

preview.onload = function() {
    var style = document.createElement('style');
        style.id = 'mycssid';
        style.type ='text/css';
        mypreview.head.appendChild(style);
}

FIDDLE

这篇关于无法在iframe头中创建STYLE标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆