Browser zoom level detection & setting?

Is there any way to detect and/or set the Web Browser’s zoom level? Seems this impacts on the available space for layout…

var screenCssPixelRatio = (window.outerWidth - 8) / window.innerWidth;
if (screenCssPixelRatio >= .46 && screenCssPixelRatio <= .54) {
  zoomLevel = "-4";
} else if (screenCssPixelRatio <= .64) {
  zoomLevel = "-3";
} else if (screenCssPixelRatio <= .76) {
  zoomLevel = "-2";
} else if (screenCssPixelRatio <= .92) {
  zoomLevel = "-1";
} else if (screenCssPixelRatio <= 1.10) {
  zoomLevel = "0";
} else if (screenCssPixelRatio <= 1.32) {
  zoomLevel = "1";
} else if (screenCssPixelRatio <= 1.58) {
  zoomLevel = "2";
} else if (screenCssPixelRatio <= 1.90) {
  zoomLevel = "3";
} else if (screenCssPixelRatio <= 2.28) {
  zoomLevel = "4";
} else if (screenCssPixelRatio <= 2.70) {
  zoomLevel = "5";
} else {
  zoomLevel = "unknown";
}

Thanks Matthew,

According to StackOverflow that works sometimes but there’s no universal means of detection. http://stackoverflow.com/questions/1713771/how-to-detect-page-zoom-level-in-all-modern-browsers

So is there a way to at least set the zoom of the page to zero in every browser?

Thanks,

Eric

That I don’t know of. I know that explorer used Screen.XDPI and Screen.YDPI, but I’ve noticed the new explorer replacement (Edge) is an entirely different beast. I’ve noted that Xojo web apps don’t really play nicely with edge, and sometimes entirely freeze the browser to the point ctl+alt+del is needed just to close edge.

The code I shared works for mozilla, firefox, and safari, edge…that’s a negative and XDPI and YDPI yield an error in edge :-/

There is. I will post the code when I am back at the office.

Matthew : If the 8 pixels you subtract to OuterWidth correspond as I think to the frame, you do not want to do that in Windows 10 with its frameless (or with a 1 pixel frame) windows.

Eric : Here is the code to set zoom level :

HTMLViewer(Win.Control(i)).ExecuteJavaScript "document.body.style.zoom=" + chr(34) + str(round((selfdims/selforg)*100))+"%" + chr(34)

I just got back, so I did not experiment, but I believe it should be possible to get the zoom level property the same way I am setting it here. The catch is, chances are the property document.body.style.zoom is undefined if no zoom has been applied. So the code must first check if the zoom exists before reading it.