网友回复
在两个不同域名的网页之间传递消息和调用方法,可以使用跨域消息传递(Cross-origin communication)技术,其中最常用的是窗口.postMessage()方法。postMessage()方法允许不同来源的窗口进行受限通信,以实现跨域消息传递。
以下是使用postMessage()的一个基本示例: 假设有两个域名:domainA.com和domainB.com。 在domainA.com中的代码示例:<!DOCTYPE html>
<html>
<head>
<title>Domain A</title>
<script>
function sendMessage() {
var iframe = document.getElementById('iframeB');
var message = {data: 'Hello from Domain A'};
iframe.contentWindow.postMessage(JSON.stringify(message), 'https://domainB.com');
}
</script>
</head>
<body>
<h1>Domain A...点击查看剩余70%


