简体   繁体   English

如何在iframe中设置图像宽度

[英]How to set width of image inside of iframe

I want to set the width of image inside of iframe. 我想在iframe中设置图片的宽度。

By default when an image is set inside iframe and if the image is in high resolution then the iframe will be scrollable 默认情况下,如果将图片设置在iframe中,并且该图片处于高分辨率状态,则该iframe将是可滚动的

If both frames are on the same domain and there is no restriction with Same Domain Policy, you can use the following code from the "parent" frame to change an image in the "child" iframe. 如果两个框架都在同一个域上,并且“相同域策略”没有限制,则可以使用“父”框架中的以下代码来更改“子” iframe中的图像。

Pseudo code, you need to actually edit it to match your DOM: 伪代码,您需要对其进行实际编辑以匹配您的DOM:

document.getElementById('iframe').contentDocument.getElementById('yourImageId').width = '100';

Notes: In case iframe is on a different domain, you have limited access for security reasons. 注意:如果iframe位于其他域中,出于安全原因,您的访问权限将受到限制。

More details here https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy 此处有更多详细信息https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM