2012-07-14 54 views
0

我与YUI 3富文本编辑器实验和跨越的事件,我不明白传来:YUI富文本编辑器和同源策略在Chrome

当我注入不同来源的iframe的编辑内区域,则此iframe的内容可以编辑为任何其他内容。我可以将光标放入iframe区域,例如删除字符。

这种情况只发生在Chrome浏览器,Firefox不能编辑iframe。尽管与YUI文本编辑器的页面不同,但内部iframe的DOM可以如何操作?

这里的例子编码:

<html> 
    <head> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
    <script src="http://yui.yahooapis.com/3.5.1/build/yui/yui-min.js"></script> 
    <script> 
    YUI().use('editor-base', function(Y) { 
     var editor = new Y.EditorBase({content: '<strong>This is <em>a test</em></strong><strong>This is <em>a test</em></strong> '}); 
     //Add the BiDi plugin 
     editor.plug(Y.Plugin.EditorBidi); 
     //Focusing the Editor when the frame is ready.. 
     editor.on('frame:ready', function() {this.focus();}); 
     //Rendering the Editor. 
     editor.render('#editor'); 
    }); 
    </script> 
    <script> 
    function inject() { 
     var ifr = $('<iframe/>', { 
     style: 'display: block; width: 300px; heigth: 200px;', 
     src: 'http://demo.yarkon.de', 
     frameBorder: 0, 
     scrolling: 'no' 
     }); 
     $('#editor').find('iframe').contents().find('body').append(ifr); 
    } 
    </script> 
    </head> 
    <body> 
    <button onclick='inject()'>Inject</button> 
    <div id="editor"></div> 
    </body> 
</html> 

谷歌Chrome浏览器20:iframe是编辑

火狐13:iframe中不可编辑

回答

1

YUI富文本编辑器创建可编辑区域的iframe和将文档的designMode设置为,并将其设置为。这意味着这个iframe及其所有后代都处于可编辑模式。如果将另一个iframe注入到可编辑区域,它将继承此属性并且也是可编辑的,与其来源无关。

因此,假设YUI文本编辑器以某种方式操纵注入的iframe的DOM是不正确的:没有涉及JavaScript,它纯粹是像任何其他可编辑字段一样的用户交互(如textarea或具有contenteditable属性的元素)。