我使用此代碼從彈出窗口中的字段獲取值。JavaScript:從彈出窗口獲取值(外部網站)
http://myotherwebsitename.com/parent.html
<input type="text" id="output"/>
<button id="show">Open</button>
<script>
document.getElementById('show').addEventListener('click', function(){
window['output'] = document.getElementById('output');
window.open('http://mywebsite.com/map.html')
});
</script>
<input type="text" id="user_text"/>
<input id="send" type='button' value'send'/>
<script>
document.getElementById('send').addEventListener('click', function(){
window.opener['output'].value = document.getElementById('user_text').value;
})
</script>
它工作得很好,如果兩者都在同一網站上託管,但如果我把其中的一個在其他網站也無法正常工作。
我如何使它適用於不同的網站?
謝謝!
你不能。同源政策禁止您訪問其他網站的內容。 – Barmar
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Same_origin_policy_for_JavaScript – Abhitalks