html - Is there a way to inject javascript code from an iframe into the parent window? -


is there way inject javascript iframe parent window using javascript? both iframe , parent in same domain.

i cannot perform action parent window after detecting changes in iframe, due other reasons.

example:

<div id="bar"> hello world </div> <iframe srcdoc="     <html>         <body>             <script type="text/javascript">                 // change "bar"'s style or alter content             </script>         </body>     </html> "></iframe> 

all need use global parent variable in iframe, either using window.parent or parent directly.

example:

<div id="bar"> hello world </div> <iframe srcdoc="<html>     <body>         <script>             window.parent.document.getelementbyid('bar').style.background = 'red';         </script>     </body> </html>"></iframe> 

so long iframe satisfy same-origin policy, work.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -