1.首先在C:\Windows\System32\drivers\etc里面添加
10.216.60.9 dfl.km.com
10.216.60.88 a.km.com
2.10.216.60.9 dfl.km.com服务器上测试a.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>A</title>
</head>
<body>
<textarea id="message">这是高层的密码!</textarea><br/>
<button id="test">看看员工在说什么</button><br/><br/><br/>员工们:<br/>
<iframe src="http://a.km.com:8080/IM_KM/avicit/b.html" width="500" height="300" id="iframe"></iframe>
<script>
document.domain = "km.com";//将两个跨域的主页面主域设为相同
document.getElementById("test").onclick = function(){
alert(document.getElementById("iframe").contentWindow.document.getElementById("message").value);
}
</script>
</body>
</html>
3.10.216.60.88 a.km.com服务器上测试b.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JSONP方式</title>
</head>
<body>
<textarea id="message">这是员工的密码!</textarea><br/>
<button id="test">看看领导在说什么</button><br/>
<script>
document.domain = "km.com";//将两个跨域的主页面主域设为相同
document.getElementById("test").onclick = function(){
alert(parent.document.getElementById("message").value);
}
</script>
</body>
</html>
这样就可以相互调用