使用iframe本身缩放iframe内容

Zooming of iframe contents with iframe itself?

本文关键字:iframe 内容 缩放 使用      更新时间:2023-09-26

我有这个代码缩放iframe

的内容
function SetZoom(){
var ZoomValue = 100;
try{
iframeDoc.body.style.zoom=ZoomValue+'%';
}catch(err){}
try{
iframe.body.style.OTransform = 'scale('+(ZoomValue/100)+')';
}catch(err){}
}

现在我需要模拟iframe的缩放比如

iframe.style.width=(??????/ZoomValue)+'px';
iframe.style.height=(??????/ZoomValue)+'px';

不知道应该用什么代替???????

** edit **这应该帮助你更好,只是调用initZoom()后iframe已添加到DOM。

var origWidth, origHeight;
// Call this once on page load
function initZoom(){
  // If you know the iframe's size is in pixels
  origWidth = parseFloat(iframe.style.width);
  origHeight = parseFloat(iframe.style.width);
}
// Call every time you change the zoom level
function zoom(size){
  iframe.style.width = (origWidth * size) + 'px';
  iframe.style.height = (origHeight * size) + 'px';
}

感谢Basic的建议。