我试图确定一个用户是否放大了他们的网页,它看起来像有几个属性可用来帮助确定他们中的一个是舞台。 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)上可以工作。
UPDATE:
下面是截图我所看到的Safari和Firefox在Mac上:
Safari浏览器(上变焦clientWidth价值变动)
火狐(无值发现变焦这一变化)
当用户转到菜单视图>缩放>增大文字大小。 html页面比例增加。在Safari中,客户端宽度增加。在Firefox中它不。我没有使用Ctrl +鼠标滚轮,但它听起来像是一样的结果。我会看设备像素比例,看看它是否会改变我。 –
我已将屏幕截图添加到原帖 –
我能说什么?我添加了gif。它适用于我的Firefox。我没有野生动物园。也许你应该为一些HTML受虐狂标记html/js来回答:P –