JavaScript - preventing page scaling

I have a web application that will be used on a tablet (in Internet Explorer). EDIT: Not a tablet, but a Windows 7 computer with a touch screen.

The problem is that the user can pinch to enlarge the page (e.g. ctrl - +).

Is there a way to disconnect it from JavaScript? (e.g. on mobile devices).

Or maybe change the User Agent, for example, like an iPad? Will this work?

+6
source share
2 answers

Use

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> 

in the <head> section of your document to prevent the website from scaling on mobile devices. The important thing here is user-scalable=no , which does the trick.

Edit

I did some more research, and you also got the opportunity to add:

 <meta name="MobileOptimized" content="640"> 

So far, content="640" is the width you want to set and behaves like <meta name="viewport" content="width=640,user-scalable=no"> .

Read more about here and here .

+6
source

You can disable browser scaling with Ctrl + or Ctrl - or with Ctrl. Key + Mouse Up or Down using this code.

 $(document).keydown(function(event) { if (event.ctrlKey==true && (event.which == '61' || event.which == '107' || event.which == '173' || event.which == '109' || event.which == '187' || event.which == '189' ) ) { event.preventDefault(); } // 107 Num Key + // 109 Num Key - // 173 Min Key hyphen/underscor Hey // 61 Plus key +/= key }); $(window).bind('mousewheel DOMMouseScroll', function (event) { if (event.ctrlKey == true) { event.preventDefault(); } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> teste 
+3
source

Source: https://habr.com/ru/post/972456/


All Articles