繁体   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