With tampermonkey I am running this Javascript inside an iframe in my page:
document.addEventListener("message", function(e){
console.log('asd');
}, false);
This way I could receive messages from parent window. I am using jQuery Mobile and have this HTML:
<div data-role="page" data-url="/scraps/new?for=http://en.wikipedia.org/wiki/List_of_hotels_in_Australia" tabindex="0" class="ui-page ui-body-c ui-page-active" style="min-height: 258px;">
<p class="notice"></p>
<p class="alert"></p>
<iframe id="test" name="scrap" src="http://en.wikipedia.org/wiki/List_of_hotels_in_Australia" width="100%"></iframe>
</div>
But when I do this in browser console:
var win = document.getElementById("test").contentWindow; // undefined
win
Unsafe JavaScript attempt to access frame with URL http://en.wikipedia.org/wiki/List_of_hotels_in_Australia from frame with URL http://localhost:3001/scraps/new?for=http://en.wikipedia.org/wiki/List_of_hotels_in_Australia. Domains, protocols and ports must match.
Unsafe JavaScript attempt to access frame with URL http://en.wikipedia.org/wiki/List_of_hotels_in_Australia from frame with URL http://localhost:3001/scraps/new?for=http://en.wikipedia.org/wiki/List_of_hotels_in_Australia. Domains, protocols and ports must match.
Unsafe JavaScript attempt to access frame with URL http://en.wikipedia.org/wiki/List_of_hotels_in_Australia from frame with URL http://localhost:3001/scraps/new?for=http://en.wikipedia.org/wiki/List_of_hotels_in_Australia. Domains, protocols and ports must match.
Unsafe JavaScript attempt to access frame with URL http://en.wikipedia.org/wiki/List_of_hotels_in_Australia from frame with URL http://localhost:3001/scraps/new?for=http://en.wikipedia.org/wiki/List_of_hotels_in_Australia. Domains, protocols and ports must match.
Window {}
win.postMessage('aaaa')
Error: SyntaxError: DOM Exception 12