代码镜像和 iFrame 问题
Codemirror and iFrame issue
我正在我的一个项目中使用 Codemirror。这里的代码:
<script>
window.onload = function() {
var te = document.getElementById("js");
var te_html = document.getElementById("html");
var te_css = document.getElementById("css");
window.editor = CodeMirror.fromTextArea(te, {
mode: "javascript",
lineWrapping: true,
});
window.editor_css = CodeMirror.fromTextArea(te_css, {
mode: "css",
lineWrapping: true,
});
window.editor_html = CodeMirror.fromTextArea(te_html, {
mode: "text/html",
lineWrapping: true,
})
};
</script>
我还使用 Jeffrey Way 的"如何将自定义 HTML 和 CSS 注入 iframe"脚本来构建类似于 Tinkerbin 或 JSFiddle 的东西。
这是我对该部分的代码:
<script type="text/javascript">
(function() {
$('.grid').height( $(window).height() );
var contents = $('iframe').contents(),
body = contents.find('body'),
styleTag = $('<style></style>').appendTo(contents.find('head'));
$('textarea').keyup(function() {
var $this = $(this);
if ( $this.attr('id') === 'html')
{
body.html( $this.val() );
}
else
{
styleTag.html( $this.val() );
}
});
})();
</script>
一切都很好,除了激活 CodeMirror 脚本后,"结果"选项卡中不会显示任何内容。如果我删除代码镜像代码部分,它可以正常工作。
这是我的项目链接:
http://mediodesign.ca/cms-test/
有人知道冲突在哪里吗?
谢谢!
确保你已经加载了所有的javascript。
mode/javascript.js
mode/css.js
mode/xml.js
如果您在 XHTML 文件中使用此脚本。 使用单引号( '
) 代替双引号( "
)
前任。
<script>
window.onload = function() {
var te = document.getElementById('js');
var te_html = document.getElementById('html');
var te_css = document.getElementById('css');
window.editor = CodeMirror.fromTextArea(te, {
mode: 'javascript',
lineWrapping: true,
});
window.editor_css = CodeMirror.fromTextArea(te_css, {
mode: 'css',
lineWrapping: true,
});
window.editor_html = CodeMirror.fromTextArea(te_html, {
mode: 'text/html',
lineWrapping: true,
})
};
</script>
Jeffrey Way的《如何将自定义HTML和CSS注入iframe》...与加载代码镜像脚本无关
相关文章:
- 由于iframe导致的问题
- 使用YouTube iFrame API的IE中的JavaScript问题
- 将HTML表单发布到iframe会导致浏览器历史记录出现问题
- 从父页面调用iframe中的javascript,IE问题
- 在Google Chrome中打印iFrame时出现问题
- 在Internet Explorer 8中的Iframe中创建TinyMCE时出现问题
- 这个基于iFrame选择器的if函数有什么问题
- 当内容显示在FireFox的iFrame中时,jQuery高度问题
- 如何应对iframe安全问题
- 使用 Iframe 问题设置跨域 Cookie
- 移动设备上的 iFrame 重定向主页问题
- iframe 的奇怪跨域问题
- Iframe 透明度问题
- 缺少 iframe ie8.相对定位不能解决问题
- HTML5验证中漂亮的照片iframe的问题
- 检测 iframe 中的连接问题
- Firefox 13 iframe 打印问题来自 JavaScript
- insertBefore() 一个 iframe jquery 问题
- 未捕获的安全错误端口问题:Iframe调整大小
- fanybox的问题.Iframe只适用于网站上的第一个链接