1

I'm using IE11 and using emulation in developer tool to change document mode to 5. Now I want to get current zoom level, I change it in setting of IE.

ie5 setting

I'm using this code to get zoom level

zoom = document.documentElement.offsetWidth / $(document).width();

But it only get zoom out (zoom level <= 100%). If zoom level > 100%, zoom = 1.

IFZR
  • 316
  • 1
  • 12
  • yeah I know but my project's requirement need to support this old browser ;) – IFZR Sep 24 '19 at 01:53
  • Nobody needs to support a browser that doesn't run on any supported operating system. Tell your client they do not need IE 5 support. – Adrian Brand Sep 24 '19 at 04:11

2 Answers2

2

there is a library for this: https://github.com/tombigel/detect-zoom

Unfortunately, it does not work well currently in Desktop browsers. But if you look at the code it might help.

The short version is that right now this is very difficult. Why are you trying to detect zoom?

Brenn
  • 1,364
  • 1
  • 12
  • 22
  • Actually, it's the newer browsers that make it hard. He'll just have to test. I'm on a mac so I really can't help there haha. – Brenn Sep 24 '19 at 01:42
2

I found this code in this library seem works for me https://github.com/tombigel/detect-zoom.

var zoom = Math.round((screen.deviceXDPI / screen.logicalXDPI) * 100) / 100;

Thanks Rampant for let me know about this library.

IFZR
  • 316
  • 1
  • 12
  • Both [deviceXDPI](https://msdn.microsoft.com/en-us/ie/ms533721(v=vs.94)) and [logicalXDPI](https://msdn.microsoft.com/en-us/ie/ms534128(v=vs.94)) were introduced in IE6. – Tyler Roper Sep 24 '19 at 02:01
  • I don't have real IE5 to test this but I when run code in console these XDPI have value – IFZR Sep 24 '19 at 02:25
  • Well, if it works it works! Just figured I'd give you a heads up. For what it's worth, looks like [Microsoft still provides an IE5 download](https://www.microsoft.com/en-us/download/details.aspx?id=53313&WT.mc_id=rss_alldownloads_all). – Tyler Roper Sep 24 '19 at 02:25