javascript - How can I read the loaded scripts in an Iframe? -
how can read loaded scripts in iframe?
i want echo variables outside iframe , utilize variables in script.js out of iframe.
my code:
<script type="text/javascript"> var myiframe = document.getelementbyid(ifr_id); var script = myiframe.contentwindow.document./*script.js*/; </script>
in iframe's <head>
: <script type="text/javascript" src="script.js"></script>
.
script.js:
$rootscope.texts = { content : 'inceptos suspendisse etiam tempor posuere volutpat tempor dapibus varius nullam sagittis nibh amet in mattis quisque, conubia tempor @ eros turpis erat, phasellus tincidunt tristique nisl.', copyright : '--- © 2014 robbiewilliams interactive. rights reserved.', };
how can load <script>'s iframe? (but want opposite)
read them out this
var scripts = myiframe.contentwindow.document.getelementsbytagname("script"); (var i=0;i<scripts.length;i++) { if (scripts[i].src) { console.log(i,scripts[i].src); } else { console.log(i,scripts[i].innerhtml); } }
that should work.
or seek using myiframe.contentwindow.document.scripts
. see https://developer.mozilla.org/en-us/docs/web/api/document.scripts
javascript jquery html iframe
No comments:
Post a Comment