2016-08-22 3 views
6

대부분은 전체 HTML 문서 (<html>...</html>) 인 샌드 박스보기로 내용을 표시해야합니다. 샌드 박스의 데이터 부분이있는 샌드 박스 처리 된 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

간단히 빈은 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(); 
}