Wednesday 15 September 2010

javascript - window.frameElement is undefined in Google Chrome when local, works when online -



javascript - window.frameElement is undefined in Google Chrome when local, works when online -

this question has reply here:

using iframe local files in chrome 3 answers

i have requirement develop web app accessed locally , offline. part of design iframe used swap out content , when needed. problem when accessed locally script works in ff 32 , ie 11 not in chrome 38. running on windows 7 sp1 64-bit.

further, when accessed server, same script works in chrome, ff , ie. have hunch caused bug in chrome. nevertheless, know if there wrong script. have provided them here :

index.html

<body> <p>this illustration demonstrates how assign "onload" event iframe element.</p> <iframe id="iframe" name="iframe" height="500px" width="500px" src="about:blank"></iframe> <p id="demo"></p> <button id="swap" onclick="swap()">swap</button> <script> function swap() { document.getelementbyid("iframe").src = "child.html"; } function myfunction() { document.getelementbyid("demo").innerhtml = "iframe loaded."; } window.onload = myfunction(); </script> </body>

child.html

<body> <h1>this page...</h1> <button onclick="next()">next</button> <script src="worker.js" type="text/javascript"></script> </body>

grandchild.html

<body> <h1 id="header"></h1> <button onclick="prev()">prev</button> <script> window.onload = function () { init(); }; </script> <script src="worker.js"></script> </body>

worker.js

function next() { window.frameelement.src = "grandchild.html"; } function prev() { window.frameelement.src = "child.html"; } function init() { var iframe = window.frameelement; var framedocument = (iframe.contentwindow || iframe.contentdocument); if (framedocument.document)framedocument = framedocument.document; framedocument.getelementbyid("header").innerhtml = "this script!!"; }

it obvious window.frameelement undefined. i'm newbie web development. help have gratitude.

after digging around lot, i've learned feature of chrome/chromium. security purposes local content blocked within iframe. there 2 possible solutions problem :

a) such utilize iframe 1 must access content web server. can accomplished serving entire app server[online] or bundling app node.js app additions.

b) possible solution replace iframe possible alternative, though not 1 solution seems simpler using iframe, imho.

since requirement deploy web app locally cd/dvd, find node.js solution attractive implies possible node-webkit deployment too.

javascript html5 google-chrome iframe

No comments:

Post a Comment