javascript - iframe contentWindow is undefined when use window.frames[name] to access -
if use following way contentwindow, value undefined
<html> <head> <title>iframe test</title> </head> <body> <iframe id="frame1" src="frame1.html" name="frame1"></iframe> <script> document.body.onload = function() { console.info("index loaded"); var frame1 = window.frames["frame1"]; console.info(frame1.contentwindow); } </script> </body> </html>
if use other way following, works fine:
var frame1 = document.getelementbyid("frame1"); console.info(frame1.contentwindow);
i tested on ff 29.0.1, chrome 34, ie11, work same way.
so have 2 questions:
- why first way can't contentwindow value
- iframe.contentwindow compatible in browser?
window.frames["frame1"];
is contentwindow
, get's named window, , in case it's same thing
document.getelementbyid("frame1").contentwindow
Comments
Post a Comment