html - Can't get same origin iframe body on IE10? -
html - Can't get same origin iframe body on IE10? -
i've created page empty iframe on it. can select iframe document , navigate it's body:
var iframe = document.getelementsbytagname('iframe')[0]; var doc = iframe.contentdocument || iframe.contentwindow.document; var body = doc.body; console.log("body is", body);
in firefox , chrome gives me body object. in ie10 gives me null.
here jsbin demonstrating issue. open js, console, output panels , click "run js".
two questions:
how access iframe's body in cross-browser manner? which right "to-spec" behavior?
i had similar problem before today. seems ie, @ to the lowest degree 9 , 10, doesn't create iframe body correctly (when used developer tools able see body tag within iframe, wasn't able phone call it), when there's no specified src. gives null cause doesn't exist.
the answer, whether there cross browser manner access iframe's body, no. but, utilize workaround. first, check if iframe body exist, if not, create it.
your code this:
var iframe = document.getelementsbytagname('iframe')[0]; var doc = iframe.contentdocument || iframe.contentwindow.document; // workaround if (doc.body == null) { // null in ie doc.write("<body></body>"); } var body = doc.body; console.log("body is", body);
source: http://forums.asp.net/t/1686774.aspx/1
html iframe internet-explorer-10 specifications
Comments
Post a Comment