2016-08-22 12 views
6

コンテンツをサンドボックス化されたビューに表示する必要があります。ほとんどの場合、フルHTMLドキュメント(<html>...</html>)です。私は、src datauriでサンドボックスのiframeを使用しています。任意の解決策/回避策は、残念ながら、それはInternet ExplorerでサポートされていませんIE-IFRAMES/Data Uri

var 
 
    iframe = document.createElement('iframe'), 
 
    content = '<html><head></head><body><h1>Hello</h1></body></html>' 
 
; 
 
iframe.sandbox = ''; 
 
iframe.src = 'data:text/html;charset=utf-8,' + content; 
 
document.body.appendChild(iframe);

... ありますか?

答えて

2

私のソリューション:

  1. はちょうど同じ起源はiframeを持つために、空のindex.htmlを作成します。
  2. アクセス
  3. は、単に空のiframeを作成し、それはコンテンツがどうなるのです交換

function ReplaceIframeContentCtrl() { 
 
    var iframe = document.getElementById('test'); 
 
    var content = "<html><head></head><body><h1>Hello</h1></body></html>"; 
 
    
 
    iframe.contentWindow.document.open(); 
 
    iframe.contentWindow.document.write(content); 
 
    iframe.contentWindow.document.close(); 
 
} 
 

 
document.addEventListener('DOMContentLoaded', ReplaceIframeContentCtrl);
<iframe id="test" src="/index.html"></iframe>

0

その内容を元に戻しJavaScriptでのiframe:

function insertIframeHtml(parent, html) { 
    const jparent=$(parent).empty(); 
    const iframe=$('<iframe></iframe>').appendTo(jparent)[0]; 
    iframe.contentWindow.document.open(); 
    iframe.contentWindow.document.write(html); 
    iframe.contentWindow.document.close(); 
}