Crocsx Crocsx - 6 months ago 250
HTML Question

Force page zoom at 100% with JS

I created a little game in Canvas, but I have a problem.

Some users who have the default zoom set to something other than 100% can't see the entire game page...

I searched on the internet for a solution to this problem but couldn't find one...

I have already used:

zoom: 100%;
in CSS.

<meta name="viewport" content="initial-scale=1.0 , minimum-scale=1.0 , maximum-scale=1.0" />


and


style="zoom: 75%"


Can someone help me please.

Thank you

Answer

You can set zoom property on page load

document.body.style.zoom = 1.0

But, zoom is not a standard property for all browsers, I recommend using transform instead.

var scale = 'scale(1)';
document.body.style.webkitTransform =  scale;    // Chrome, Opera, Safari
 document.body.style.msTransform =   scale;       // IE 9
 document.body.style.transform = scale;     // General

http://jsfiddle.net/5RzJ8/