[英]How to change Iframe width inside an iframe?
我在包含子Iframe的網頁中有一個Iframe。 我想使用jquery更改子iframe寬度。 請注意,內部iframe沒有ID。 我怎樣才能做到這一點 ? (兩個iframe都來自我的域)
非常感謝你
<Iframe id="iframeDoc ">
// some codes
<Iframe>
// another page codes
</Iframe>
</Iframe>
我已經嘗試過這些代碼,但是沒有人工作!
$('#iframeDoc > iframe').width("400px");
$('#iframeDoc iframe').width("400px");
$('#iframeDoc').contents().find("iframe").width("400px");
您可以使用contentWindow
選擇嵌套的iframe:
let pageiFrame = document.getElementById('iframeDoc')
let nestediFrame = pageiFrame.contentWindow.document.getElementBySelector('iframe')
pageiFrame.style.width = '400px'
nestediFrame.style.width = '400px'
如果您的iframe位於其他域上,這可能會很有用。
嘗試查看Window.postMessage()
方法。 您可以在iframe和window.addEventListener('message', messageHandlerFn)
外部使用它。
但這僅在您有可能在iframe之外修改源的情況下才適用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.