javascript - In Chrome, can't access any variables or functions of a child iframe, or of an iframe's parent -
this similar this question, although bit broader.
i'm opening these pages locally, , sit in same folder.
index.html:
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html lang="en"> <head> <title>testindex</title> <script type="text/javascript"> function init() { alert("child.childvar: " + child.childvar); //works in ff, ie, not chrome alert("frames['child'].childvar: " + frames['child'].childvar); //works in ff, ie, not chrome alert("document.getelementbyid('child').contentwindow['childvar']: " + document.getelementbyid('child').contentwindow['childvar']); //works in ff, ie, not chrome child.childfunc(); //works in ff, ie, not chrome frames['child'].childfunc(); //works in ff, ie, not chrome document.getelementbyid('child').contentwindow['childfunc()']; //doesn't work in } var parentvar = 7; function parentfunc() { alert("in parentfunc"); } window.onload = init; </script> </head> <body> <iframe id="child" name="child" src="child.html">your browser not support iframes</iframe> </body> </html> child.html:
<!doctype html public "-//w3c//dtd html 4.01//en" "http://www.w3.org/tr/html4/strict.dtd"> <html lang="en"> <head> <title>testchild</title> <script type="text/javascript"> function init() { alert("parent.parentvar: " + parent.parentvar); //works in ff, ie, not chrome parent.parentfunc(); //works in ff, ie, not chrome } var childvar = 5; function childfunc() { alert("in childfunc"); } window.onload = init; </script> </head> <body> </body> </html> i can't seem achieve communication @ between page , iframe's content in chrome. did read answers question linked to, don't know userscripts/content scripts are, don't know how relevant questions mine.
i guess actual question is: how hell values iframe'd page parent page!?
apparently javascript inter-frame communication doesn't work when on local file system. put files on server , function expected.
Comments
Post a Comment