Opera9.5 关于IFRAME编辑模式的小问题

editFrameWindow  →  IFRAME对象.contentWindow

1  editFrameWindow.document.designMode  =   ' On ' ;
2  editFrameWindow.document.open();
3  editFrameWindow.document.writeln( ' <html><head> ' );
4  editFrameWindow.document.writeln( ' </head><body></body></html> ' );       
5  editFrameWindow.document.close();


在IE6+,Opera9+(不包括9.5),FF2+ ,Safari 下都可以正常编辑,到了Opera9.5 这样写的话该IFRAME将不可以编辑,也不报错。问题出在这里:

1  editFrameWindow.document.open();
2  editFrameWindow.document.writeln( ' <html><head> ' );
3  editFrameWindow.document.writeln( ' </head><body></body></html> ' );       
4  editFrameWindow.document.close();

这段代码是为了让FF2+正常编辑而写的,其他浏览器都则可以忽视这一段代码,不过现在Opera9.5已经不能忽视了。

解决办法就是针对FF2+(Gecko内核)的浏览器 判断执行。



1  editFrameWindow.document.designMode  =   ' On ' ;
2  if (navigator.userAgent.indexOf( ' Gecko ' >   - 1   &&  navigator.userAgent.indexOf( ' KHTML ' ==   - 1 ) {
3      editFrameWindow.document.open();
4      editFrameWindow.document.writeln( ' <html><head> ' );
5      editFrameWindow.document.writeln( ' </head><body></body></html> ' );       
6      editFrameWindow.document.close();
7  }


你可能感兴趣的:(iframe)