javascript - How do I inject a function declared in the parent page into an iframe, then call it? -
i can inject iframe this:
iframe.contentwindow.action...
however, if want send function declared within iframe, , call it?
e.g.
function hello(){...} iframe.contentwindow...
and both declare , call hello
within iframe?
just clarify, hello
's actions should done inside iframe. example, if put document.getelementbyid("input").value="foo";
inside hello
, call inside iframe, changes should take effect inside input
inside iframe , not in parent window.
insert script tag <head>
section of frame code in it. script tag can either external script reference or inline script. have same origin in order injection.
var idoc = iframe.contentwindow.document; var script = idoc.createelement("script"); script.textcontent = 'document.getelementbyid("input").value="foo";' idoc.getelementsbytagname("head")[0].appendchild(script);
Comments
Post a Comment