iframejs跨域访问
发布时间: 2023-01-03 19:37:50
① 如何用javascript 跨域获取iframe子页面的元素信息
跨域的话想用父页面的js获取iframe里的元素是不可能的。
用chrome扩展程序的话是可以的。
② 如何用js操控iframe引用的跨域网站
<body>
<buttonid="btn">submit</button>
<iframesrc="http://www..com"id="frame"frameborder="0"></iframe>
</body>
<script>
varbtn=document.getElementById('btn');
varfr=document.getElementById('frame');
btn.addEventListener("click",function(){
fr.contentWindow.location.href="http://www.2345.com";
});
</script>
给按钮绑定个事件吧然后执行iframe.location.href="新闻页地址";
③ JS跨域访问操作iframe代码
没太明白你的意思,如果是让iframe跟着主窗口大小走,那么只需要设置iframe的大小就可以了。
<html>
<body>
<iframe width="100%" height="100%" src="b.html" id="frm">
</iframe><br>
输入宽:<input name="myWidth"><br>
输入高:<input name="myHeight"><br>
<input type="button" value="调整大小" onClick="fun()">
</body>
</HEAD>
</HTML>
<script>
function fun(){
var myWidth = document.getElementById("myWidth").value;
var myHeight = document.getElementById("myHeight").value;
window.resizeTo(myWidth,myHeight);
}
</script>
补充:
你的意思说,A页面有多大,你的B页面就有多大,把整个屏幕撑满,是这个意思吗?
热点内容