0

tampermonkeyを使用して、ページの iframe 内でこの Javascript を実行しています。

document.addEventListener("message", function(e){
  console.log('asd');
}, false);

このようにして、親ウィンドウからメッセージを受け取ることができました。jQuery Mobile を使用しており、次の 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>

しかし、ブラウザコンソールでこれを行うと:

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
4

0 に答える 0