簡體   English   中英

如何更改 iframe 的高度和寬度?

[英]How to change height and width of an iframe?

我從另一個網站 ( dublins ) 獲得了這個書簽代碼,但我想修改它並將高度和寬度更改為頁面的 100%。 我會自己做,但我不知道如何使用 javascript。謝謝!

javascript:var url = prompt('What site do you want to embed into '+__uv.$get(location).href+'?%27);var%20prefix%20=%20%27https://%27;%20if%20(url.substr(0,%20prefix.length)%20!==%20prefix)%20{%20url%20=%20prefix%20+%20url;%20}%20var%20ifra=document.createElement(%27iframe%27);ifra.src=url;ifra.setAttribute(%27height%27,%27770%27);ifra.setAttribute(%27width%27,%271365%27);void(document.body.appendChild(ifra));

new iframe的大小由此設置。

ifra.setAttribute(%27height%27,%27770%27);ifra.setAttribute(%27width%27,%271365%27);

解碼為正常的 JavaScript 會產生以下結果

ifra.setAttribute('height','770');
ifra.setAttribute('width','1365');

這里的寬度和高度是用屬性設置的,但是屬性不能根據頁面大小來指定大小。 因此,按如下方式使用 CSS。

ifra.style.height='100vh';
ifra.style.width='100vw';

現在我們需要做的就是把它放回小書簽中。 將第一部分替換為以下內容。

ifra.style.height=%27100vh%27;ifra.style.width=%27100vw%27;

因此,完整的小書簽如下。

javascript:var url = prompt('What site do you want to embed into '+__uv.$get(location).href+'?%27);var%20prefix%20=%20%27https://%27;%20if%20(url.substr(0,%20prefix.length)%20!==%20prefix)%20{%20url%20=%20prefix%20+%20url;%20}%20var%20ifra=document.createElement(%27iframe%27);ifra.src=url;ifra.style.height=%27100vh%27;ifra.style.width=%27100vw%27;void(document.body.appendChild(ifra));

但很抱歉,我沒有測試它,因為你的書簽對我不起作用。

 <iframe style="width: 100px; height: 100px; background: red"></iframe>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM