html - 数据 :image/jpg;base64 open and resize/zoom-out in new tab

标签 html css

我有一个 input type=file 的预览按钮在新选项卡上打开所选图像的元素:

var image = new Image();
image.src = "data:image/jpg;base64," + myImageDataUrl;

var w = window.open("");
w.document.write(image.outerHTML);

问题是超过浏览器高度和宽度的图像将以全尺寸显示,要求用户使用窗口的滚动条来查看图像。有没有办法调整/缩小图像小于或等于浏览器的尺寸?

我试过将图像包装成 <div style='max-height: 100%; max-width: 100%'>没有成功。

最佳答案

您需要将图像的高度和宽度设置为 100%。

image.height = '100%';
image.width = '100%';

关于html - 数据 :image/jpg;base64 open and resize/zoom-out in new tab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53213813/

相关文章:

html - 如何添加过渡到 .class :not(:hover)?

javascript - 无法隐藏 <em>-Element,它在 Javascript 中作为 String 添加; textContent 不隐藏

css - 显示错误后控件移动

html - 如何使用 CSS 和 HTML 将文本添加到圆圈上?

javascript - 如何垂直对齐具有不同高度的div?

jquery - 谁能解释一下为什么这个 Transition 不起作用?

html - 通过点击纯 CSS 的链接来移动元素

javascript - 这是一种向链接添加标题属性的不切实际的方法吗?

javascript - jQuery 在 Phonegap 中加载本地 html 文件

javascript - 带有 'input-group-append' 的 CSS Bootstrap 4 类无法正常工作。上周Styles的展示是对的