javascript - How create iframe with XHTML content (So I can later access it)? -


i know 2 ways how fill iframe content js.

1.

var pr_cont = '<h1>hello world html</h1>';     var iframe = document.getelementbyid('printframe'); var doc = iframe.contentwindow.document doc.open(); doc.write(pr_cont); doc.close(); 

this way works, default content created html.

2.

var pr_cont = '<h1>hello world xhtml</h1>'; var iframe = document.getelementbyid('printframe'); iframe.src = 'data:application/xhtml+xml; charset=utf-8,' + pr_cont; 

seems works too, later can't access content. every time when try access content have error "securityerror: blocked frame origin"

demonstration here: https://jsfiddle.net/8ytautre/


Comments