2017-04-11 68 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 –