javascript - append meta tag to the head of the main document from iframe -
so i've got issue i've made document responsive it's displayed in iframe parent document has wrong meta tag.
i set test see if in iframe. it's appending meta tag head of iframe not main document. have suggestions?
index.html
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>iframe test</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> </head> <body> <iframe id="testframe" name="testframe" src="iframe.html"></iframe> </body> </html>
iframe.html
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>iframe</title> <script> var viewporttag=document.createelement('meta'); viewporttag.id="viewport"; viewporttag.name = "viewport"; viewporttag.content = "width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"; document.getelementsbytagname('head')[0].appendchild(viewporttag); </script> </head> <body> iframe original content </body> </html>
you can it, if domain of iframe same of top document's domain.
just change code to:
window.parent.document.getelementsbytagname('head')[0].appendchild(viewporttag);
Comments
Post a Comment