js跨域取iframe中的元素 JS出于安全性的考虑,是禁止不同域间访问对方元素的。楼主试试修改两个页面的domain属性,看看行不行。引用2L的话,明知不可为而为之,就当自己是小白鼠吧。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 A域名a.html: <script type="text/javascript">document.domain='a.com';</script><iframe src="b域名/b.html" width="1000" height="0" border="0" marginwidth="0" marginheight="0" frameborder="no" scrolling="no" allowtransparency="yes" id="iframe" name="iframe"></iframe> a_proxy.html:<head></head><body><script>function pseth() { var iObj = parent.parent.document.getElementById('iframe'); var iObjH = window.location.hash; var height = parseInt(iObjH.split("#")[1]); if (height < 560) { height = 560; } iObj.style.height = height+"px";}try { document.domain='a.com'; pseth();} catch(e){}</script></body></html>B域名b.html:增加代码<script type="text/javascript"> function setHeight(){ var dHeight = document.documentElement.scrollHeight; var t = document.createElement("div"); t.innerHTML = '<iframe id="iframeagent" src="a域名/a_proxy.html#'+dHeight+'"scrolling="yes" height="0px" width="0px"></iframe>'; document.documentElement.appendChild(t.firstChild); } </script> <body onload="javascript: setHeight();">详情请看资讯网http://www.eeite.com/a/qianduan/20140513/25.html 求一个js的标尺 <input type=submit时,onClick="if ( $(就失效了 简单问题 在线等待 如何在网页中播放音频 用javascript 如何修改 ASP中的数组? 关于美国大选有错吗? 密码修改用javascript怎么控制??请教大虾 框架问题。 怎样实现这样的功能? firefox扩展中js中文显示乱码问题 jquery变量字符串 sea wolf —— 我又无耻的在做canvas游戏了
a.html: <script type="text/javascript">document.domain='a.com';</script><iframe src="b域名/b.html" width="1000" height="0" border="0" marginwidth="0" marginheight="0" frameborder="no" scrolling="no" allowtransparency="yes" id="iframe" name="iframe"></iframe> a_proxy.html:
<head></head>
<body>
<script>
function pseth() {
var iObj = parent.parent.document.getElementById('iframe');
var iObjH = window.location.hash;
var height = parseInt(iObjH.split("#")[1]);
if (height < 560) {
height = 560;
}
iObj.style.height = height+"px";
}
try {
document.domain='a.com';
pseth();
} catch(e){}
</script>
</body>
</html>B域名
b.html:增加代码<script type="text/javascript">
function setHeight(){
var dHeight = document.documentElement.scrollHeight;
var t = document.createElement("div");
t.innerHTML = '<iframe id="iframeagent" src="a域名/a_proxy.html#'+dHeight+'"scrolling="yes" height="0px" width="0px"></iframe>';
document.documentElement.appendChild(t.firstChild);
}
</script> <body onload="javascript: setHeight();">
详情请看资讯网http://www.eeite.com/a/qianduan/20140513/25.html