开发者

Android/iOS mobile browser - disable events

开发者 https://www.devze.com 2023-03-12 11:41 出处:网络
How can I disable default mobile browser events like zoom (dblclick, expand) and options (when you hold down your finger on a screen a popup appears with options)?

How can I disable default mobile browser events like zoom (dblclick, expand) and options (when you hold down your finger on a screen a popup appears with options)?

I tried this:

document.addEventListener('ontouchstart', function(event) 
{
event.preventDefault开发者_如何学Go();
}, false);


You can prevent the finger move(scroll the page) like this:

document.addEventListener('ontouchstart', function(e) {
    e.preventDefault();
});

document.body.addEventListener('touchmove', function(e) {
    e.preventDefault();
});

And the zoom you just need to adjust the viewport like this:

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


If you set user-scalable=no, then minimum-scale and maximum-scale are ignored. So if you want to disable zoom, you should use this:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号