accessing iframe in ios phonegap
i have hard time getting phonegap(2.9.0) access iframe on ios (6.0.1).
the index.html of application consists of iframe , function check if can read content of frame after loaded.
application index.html
<!doctype html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> <script type="text/javascript" charset="utf-8" src="./phonegap.js"></script> <title>test</title> </head> <body style="background-color: #000;"> <iframe name="framewrap" id="framewrap" style="border:0;position: absolute; top: 0; left: 0;width: 100%; height:100%; background-color: #fff;" src="http://www.somedomain.de/somepath/index.html"> </iframe> <script type="text/javascript"> window.settimeout(go, 2000); function go(){ iframe = document.getelementbyid('framewrap'); innerdoc = iframe.contentwindow; alert(innerdoc.document.getelementbyid('canvas')); } </script> </body> </html> the document within iframe:
<!doctype html> <html> <head> <meta charset="utf-8" /> <script type="text/javascript"> alert('iframe loaded'); </script> <title>test</title> </head> <body style="margin:0;"> <canvas id="canvas" style="position: absolute; top:0; left:0;"> <p>your browser not support canvas element.</p> </canvas> </body> </html> what happens:
if build application , run on android(4.2.2) frame loaded, 1 alert tells me iframe loaded , alert dialog pops telling me there htmlcanvaselement. if open app on ipod touch alert dialog telling me "null". absence of iframe loaded alert indicating iframe not loaded @ all.
i have tried lot of things working failed , since don't own mac not able debug things right. -thx apple-
what suspect:
the html file bundled app executed file , uses file protocol. iframe uses httpprotocol. hence same origin policy kicks in , cant access iframe.
why not sure:
but mean inconsistent behavior across platforms since working on android. not convinced suspicion correct. furthermore lack of iframe loaded alert hint same-origin-policy not problem because @ least frame should load on desktop same-origin-policy prevents canvas alert show.
therefore:
is suspicion correct?
is there way make work across platforms?
i thankful advice , hope can me.
thanks taking time read trough!
i'm no expert in iframe, i'll give hint .. use load function of jquery out instead of iframe (http://api.jquery.com/load/) or can return html-shaped return data , display in div ...
maybe simpler alternative iframe trying mount ...
Comments
Post a Comment