I know it sounds weird but there really is a reason and it is in the users' best interest. I know that having the browser automatically maximize and set 100% might be problematic but how about making so that if the window is not maximized and the zoom is not 100% all the users would see is a message "please max your window and set the zoom to 100%". I need to make this work in Chrome, Firefox and IE ...at least.
I am not trying to make it "full screen mode" just maximize the window.
If "forcing" in the sense "keeping" 100% and max window is problematic how about just setting the zoom to 100% and maximizing the window on initial load?
Detect if at max width:
You'll probably want to check if the document's width is lesser than the screen width:
var isAtMaxWidth = screen.availWidth - window.innerWidth === 0;
You can't do this with height however, as the browser has reserved vertical space for tabs and toolbars, and there is no way of getting the height of those.
Detect browser zoom:
Based on this answer by user800583, here's a shortened version:
var screenPixelRatio = (window.outerWidth - 8) / window.innerWidth;
var isAtDefaultZoom = screenPixelRatio > 0.92 && screenPixelRatio <= 1.10;
N.B.: You can't use window.devicePixelRatio
to detect this, as high-DPI (e.g.: retina) displays will have different base values.
Combined check:
var isMaximizedAndDefaultZoom = isAtMaxWidth && isAtDefaultZoom;
Tested and working on Chrome 64 as of 06 Mar 2018
来源:https://stackoverflow.com/questions/49003290/detect-if-browser-window-is-maximized-and-at-default-100-zoom