File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,12 +26,6 @@ const BasicEditor = () => {
2626 }
2727
2828 const iframe = iframeRef . current ;
29- const document = iframe . contentDocument ;
30-
31- if ( ! document ) {
32- alert ( "iframe contentDocument is not available" ) ;
33- return ;
34- }
3529
3630 const documentContents = `
3731 <!DOCTYPE html>
@@ -46,9 +40,7 @@ const BasicEditor = () => {
4640 </html>
4741 ` ;
4842
49- document . open ( ) ;
50- document . write ( documentContents ) ;
51- document . close ( ) ;
43+ iframe . srcdoc = documentContents ;
5244 } , [ html , css , js ] ) ;
5345
5446 return (
@@ -210,7 +202,12 @@ const BasicEditor = () => {
210202 </ div >
211203 </ div >
212204
213- < iframe ref = { iframeRef } className = "output_container" id = "preview" />
205+ < iframe
206+ ref = { iframeRef }
207+ className = "output_container"
208+ id = "preview"
209+ sandbox = "allow-scripts"
210+ />
214211 </ div >
215212 </ div >
216213 ) ;
You can’t perform that action at this time.
0 commit comments