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

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -