简体   繁体   English

在Ipad safari浏览器上点按一会儿,禁用默认功能

[英]Disable the default function when tap a while on the Ipad safari browser

Default keeping tap on the screen (eg. hold tap for 1 second) will show a option of save image / copy . 默认保持点击屏幕(例如,按住1秒钟)将显示保存图像/复制的选项 However , I would like to turn off that function for my web app , is it possible? 但是,我想关闭我的网络应用程序的功能,是否可能? I have tried to replace the event of touchmove to selectall , however it does not work . 我试图将touchmove的事件替换为selectall,但它不起作用。 Thanks for helping. 谢谢你的帮助。

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

It could be beneficial to disable not only preventDefault, but other properties as well: 不仅可以禁用preventDefault,还可以禁用其他属性:

e.preventDefault(); 
e.cancelBubble = true;
e.returnValue = false;
return false;

Also the event, are you sure it's touchmove ? 事件,你确定它是touchmove?

I thought it would be worth mentioning that you can do this with pure CSS. 我认为值得一提的是你可以用纯CSS做到这一点。 It's probably not a really great idea, because neither IE10 or Opera Mobile support it. 这可能不是一个好主意,因为IE10或Opera Mobile都不支持它。 But it can be done, and in the future, this would probably be a better way than with JavaScript. 但它可以完成,并且在未来,这可能是比使用JavaScript更好的方式。 Or if you're only talking about iPhones and iPads, this method would work really well. 或者,如果你只是谈论iPhone和iPad,这种方法将非常有效。 Here's an example on CodePen . 这是CodePen的一个例子。

The code is simple: 代码很简单:

.notouch {
    pointer-events: none;
}

Just give the class of notouch to any image that you want to effect. 只需将类别notouch您想要影响的任何图像。

If you want to do it to every image on the page, do this: 如果要对页面上的每个图像执行此操作,请执行以下操作:

img {
    pointer-events: none;
}

And I should give an obligatory speech on useability. 我应该就可用性发表强制性演讲。 By doing this you're overriding default functionality that people expect to be there all the time. 通过这样做,您可以覆盖人们希望始终存在的默认功能。 It makes for a really bad experience for you to turn off something like this, unless you have a really, really good reason to do so. 除非你有一个非常非常好的理由,否则这会给你带来非常糟糕的体验。 So please, make sure you do. 所以,请确保你这样做。

Edit : 编辑

To get rid of the magnifying glass, use this code: 要摆脱放大镜,请使用以下代码:

.notouch {
    pointer-events: none;
    -webkit-user-select:none;
}

With -webkit-user-select set to 'none' you may not even need to turn off pointer events, but I'm not sure about that. 使用-webkit-user-select设置为'none',您甚至可能不需要关闭指针事件,但我不确定。 I updated the CodePen as well. 我也更新了CodePen。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM