How to prevent zoom on chrome, firefox, safari?
Try this
$(window).bind('mousewheel DOMMouseScroll', function(event) {
if(event.ctrlKey == true)
{
event.preventDefault();
if(event.originalEvent.detail > 0) {
console.log('Down');
}else {
console.log('Up');
}
}
});
Disable zoom in browser JS
I believe that it is not possible to achieve this, seeing as most browser zoom functions are most definitely hard coded and forced.
The only (cheaty/somewhat regretful) solution that I've seen being used is the following:
<script>
document.firstElementChild.style.zoom = "reset";
</script>
(Which you could easily put as css too). Disabling zoom is not the best solution. Especially if the project that you are working on possibly consists of a lot of text. Zooming function adds readability and increases accessibility to your website, especially for aid of those with bad sight.
How to prevent native browser default pinch to zoom behavior?
I accidentally found a solution which works on Chrome. You basically have to preventDefault
the "wheel"
event. ctrlKey
will be true
if it is a pinch event instead of a scroll.
element.addEventListener('wheel', event => {
const { ctrlKey } = event
if (ctrlKey) {
event.preventDefault();
return
}
}, { passive: false })
I'd guess this is how Google Maps does it.
The (most) cross-browser solution is probably a combination of the techniques mentioned: user-scalable=no
in the "viewport"
meta tag for the browsers that do support it and this one for native Chrome.
How to disable page zoom in chrome
For those who may encounter this annoying problem. you only need to use vh
and vw
in all of your sizes (fonts, elements, etc...) instead of px
and em
.... those units do not follow page zoom!
Disable zooming of the page in desktop web browsers using Javascript/Jquery
var zoomlevel=1;
$("body").dblclick(function(ev) {
zoomlevel = zoomlevel == 1 ? 2 : 1;
$(this).css({
"-moz-transform":"scale("+zoomlevel+")",
"-webkit-transform":"scale("+zoomlevel+")",
"-o-transform":"scale("+zoomlevel+")",
"-ms-transform":"scale("+zoomlevel+")"
});
});
Related Topics
How to Pass Variables and Data from PHP to JavaScript
How to Save an Html5 Canvas as an Image on a Server
Load More Posts Ajax Button in Wordpress
What Are Cookies and Sessions, and How Do They Relate to Each Other
Angularjs Post Fails: Response For Preflight Has Invalid Http Status Code 404
How to Show Progress Bar While Loading, Using Ajax
Encryption in JavaScript and Decryption With PHP
Send Formdata and String Data Together Through Jquery Ajax
How to Use a C++ Library from Node.Js
How to Scroll to an Element Inside a Div
Onchange Event Handler for Radio Button (Input Type="Radio") Doesn't Work as One Value
How to Stop a Web Page from Scrolling to the Top When a Link Is Clicked That Triggers JavaScript
Detect Which Word Has Been Clicked on Within a Text
Disable Pasting Text into HTML Form
How to Get Selected Text from a Textbox Control With JavaScript