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頁面就有多大,把整個屏幕撐滿,是這個意思嗎?
熱點內容