如何让浏览器缩放因子起作用?

时间:2017-04-11 15:07:53

标签: actionscript-3 flash

我试图确定用户是否放大了他们的网页,看起来有一些属性可用于帮助确定其中一个属于舞台。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>

我还在HTML包装页面中将browserzoom设置为scale和noscale。这两种选择似乎都没有做任何事情。默认情况下应启用浏览器缩放。

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

  • 关于浏览器缩放系数的Adobe博客post
  • 在Flash Player 21上发布notes

更新
以下是我在Safari和Mac上看到的内容的截图:

Safari(clientWidth值在缩放时更改)
Safari

Firefox(没有找到更改变焦值的值)
Firefox

1 个答案:

答案 0 :(得分:0)

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

我也很难确定页面的大小,而这似乎只是在缩放页面时会发生变化的属性

window.onbeforeunload = function(){
  var input19 = $('#input19').val();
  createCookie(input19,'your-site-cookie',7);
};

window.onload = function(){
  var inputx = readCookie('your-site-cookie');
  if (inputx) {
    $('#input19').attr("value", inputx);
  }
};

function createCookie(name,value,days) {
    var expires = "";
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days*24*60*60*1000));
        expires = "; expires=" + date.toUTCString();
    }
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

此外,您可能希望获得scrollWidth/Height而不是clientWidth / Height

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