jahu jahu - 4 months ago 15x
HTML Question

How to access the contents of an iframe in nw.js?

I need to capture the contents of an iframe in nw.js. The page is located on a different domain. I tried to access it normally (

), but I get an empty html document (probably some form of cross domain security or other). I can however access the contents of the iframe from console and I'm guessing there is some setting I'm missing that will allow me to do the same directly from my code. I don't need however the iframe to be able to access nw.js (for security reasons it'll be even better if it's impossible).

<iframe src="http://google.com" width="800" height="600" id="myIframe"></iframe>
// Making sure it's actually loaded with help of jquery
$('#myIframe').ready(function () {
// Returns:
// <html>
// <head></head>
// <body></body>
// </html>


So it turns out I can access the contents of the iframe just like that in nw.js and I was just doing something wrong in my original code.

The problem was the use of jquery ready. When I tried to access the iframe when ready was triggered, I got an empty document, but when I did the same from iframe's onload callback, I actually got all the contents.

<iframe src="http://google.com" width="800" height="600" id="myIframe" onload="loaded()"></iframe>
    function loaded()
        // Returns the actual page

P.S. It is advised to use nwdisable and nwfaketop attributes when loading unsafe content (such as external site) into an iframe in nw.js.

<iframe src="http://google.com" width="800" height="600" nwdisable nwfaketop></iframe>