2017-04-11 71 views
3

我试图确定一个用户是否放大了他们的网页,它看起来像有几个属性可用来帮助确定他们中的一个是舞台。 browserZoomFactor。我试过的任何东西都在改变价值。它始终是1如何让浏览器缩放因子起作用?

这里是我使用的代码:

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" 

       minWidth="955" minHeight="600" 
       applicationComplete="application1_applicationCompleteHandler(event)"> 

    <fx:Script> 
     <![CDATA[ 
      import mx.events.FlexEvent; 

      protected function getZoomInfo():void { 
       var clientWidth:int; 
       var scaleFactor:Number 

       if (ExternalInterface.available) { 
        ExternalInterface.marshallExceptions = true; 
        clientWidth = ExternalInterface.call(string, ExternalInterface.objectID); 
        scaleFactor = Number(Number(stage.stageWidth/clientWidth).toFixed(1)); 
       } 

       zoomFactorLabel.text = ""; 
       zoomFactorLabel.text += "Client width: "+clientWidth + "\n"; 
       zoomFactorLabel.text += "Stage width: "+stage.stageWidth + "\n"; 
       zoomFactorLabel.text += "Calculated Scale factor: "+scaleFactor + "\n"; 
       zoomFactorLabel.text += "Browser Zoom factor: "+stage.browserZoomFactor + "\n"; 
       zoomFactorLabel.text += "Content Scale Factor: "+stage.contentsScaleFactor + "\n"; 
       zoomFactorLabel.text += "DPI: "+applicationDPI; 
      } 

      protected function application1_applicationCompleteHandler(event:FlexEvent):void { 
       stage.addEventListener(Event.BROWSER_ZOOM_CHANGE, browserZoomChange); 
       getZoomInfo(); 
      } 

      protected function browserZoomChange(event:Event):void { 
       trace("Zoom changed"); 
       zoomFactorLabel.text = "Zoom changed"; 
      } 

     ]]> 
    </fx:Script> 

    <fx:Declarations> 
     <fx:String id="string"><![CDATA[ 
function(clientId) { 
    var clientWidth = document.getElementById(clientId).clientWidth; 
    return clientWidth; 
} 
     ]]></fx:String> 
    </fx:Declarations> 

    <s:TextArea id="zoomFactorLabel" horizontalCenter="0" verticalCenter="-60"/> 
    <s:Button label="check browser zoom" click="getZoomInfo()" horizontalCenter="0" verticalCenter="30"/> 

</s:Application> 

我还设置了browserzoom规模和noScale,则在HTML包装程序页面。而这两种选择似乎都没有做任何事。浏览器缩放应该默认启用。

如果我手动获取swf对象的客户端宽度,我可以将其与舞台宽度进行比较并获得比例因子,但在Firefox(Mac)中不起作用,它在Safari(Mac)上可以工作。

  • Adob​​e Blog post关于浏览器缩放系数。在notes
  • 发布的Flash Player 21

UPDATE:
下面是截图我所看到的Safari和Firefox在Mac上:

Safari浏览器(上变焦clientWidth价值变动)
Safari

火狐(无值发现变焦这一变化)
Firefox

回答

0

您是否试图在用户ctrl + MouseWheeled html页面后获取swf的大小?如果你缩小整个页面,我认为clientWidth不会改变。你试过window.devicePixelRatio吗?

我也挣扎判断网页的大小和,似乎是只有当你放大你的网页,其中改变属性

function printDispSettings(){ 
    t = ""; 
    t += "wins: " + (w===window) + "\n"; 
    w = window; 
    t += "Hello\n"; 
    t += "screen:  " + screen.width +  " x " + screen.height + "\n"; 
    t += "screen.avail: " + screen.availWidth + " x " + screen.availHeight + "\n"; 
    t += "screen.aTL: " + screen.availTop + " x " + screen.availLeft + "\n"; 
    t += "screen.TL: " + screen.top + " x " + screen.left + "\n"; 
    t += "pixDepth: " + screen.pixelDepth + "\n"; 
    t += "colDepth: " + screen.colorDepth + "\n"; 
    t += "pixRatio: " + window.devicePixelRatio + "\n"; 
    t += "win.Inner: " + window.innerWidth + " x " + window.innerHeight + "\n"; 
    t += "win.Outer: " + window.outerWidth + " x " + window.outerHeight +"\n"; 
    //t += "win.Inner: " + window.innerWidth + " x " + window.innerHeight + "\n"; 
    t += "win.TopLeft: " + window.scrollX + " x " + window.scrollY +"\n"; 
    t += "F " + c + "\n"; 
    t = repStr(t,10); 
    //document.writeln("<pre>" + s + "</pre>"); 
    //p.innerHTML = s; 
} 

你也可以想scrollWidth/Height代替clientWidth的/身高

更新 - 适用于我的Firefox: enter image description here

+0

当用户转到菜单视图>缩放>增大文字大小。 html页面比例增加。在Safari中,客户端宽度增加。在Firefox中它不。我没有使用Ctrl +鼠标滚轮,但它听起来像是一样的结果。我会看设备像素比例,看看它是否会改变我。 –

+0

我已将屏幕截图添加到原帖 –

+0

我能说什么?我添加了gif。它适用于我的Firefox。我没有野生动物园。也许你应该为一些HTML受虐狂标记html/js来回答:P –