[英]How to disable magnifying glass in iPadOS15 safari
I want to disable text magnifying glass that appears when we long press on any html element.我想禁用当我们长按任何 html 元素时出现的文本放大镜。
It has started to appear again in IOS15.在IOS15中又开始出现了。
I tried the following methods, but they did not work on iOS15.我尝试了以下方法,但它们在 iOS15 上不起作用。 Disable magnifying glass in iOS html app 在 iOS html 应用程序中禁用放大镜
Do you know of any CSS properties or other ways to disable it?您知道任何 CSS 属性或其他禁用它的方法吗?
Disabling text selection with -webkit-user-select: none;
使用-webkit-user-select: none;
禁用文本-webkit-user-select: none;
did not work for me.对我不起作用。 I must use @Zhen Yao approach with calling event.preventDefault()
in the touchstart event.我必须使用@Zhen Yao方法在 touchstart 事件中调用event.preventDefault()
。
Additionally: You can disable the magnifying glass on the entire document or on a specific element , depending on which element you call the touchstart event.另外:您可以在整个文档或特定元素上禁用放大镜,具体取决于您调用 touchstart 事件的元素。
/* disable on entire document */
//var htmlElement = document;
/* disable on specific html element */
var htmlElement = document.getElementById( 'some-html-id' );
htmlElement.addEventListener('touchstart', function( event ) {
event.preventDefault();
}, false);
Sample fiddle: https://jsfiddle.net/p3y71zL4/3/示例小提琴: https : //jsfiddle.net/p3y71zL4/3/
The feature was brought back in iOS 15, see https://9to5mac.com/2021/06/07/ios-15-brings-back-the-magnifying-glass-for-accurate-text-selection/该功能已在 iOS 15 中恢复,请参阅https://9to5mac.com/2021/06/07/ios-15-brings-back-the-magnifying-glass-for-accurate-text-selection/
One solution is to handle the "touchstart"
event and call event.preventDefault()
in your handler.一种解决方案是处理"touchstart"
事件并在处理程序中调用event.preventDefault()
。
Note that the above solution does not work if you still want to handle events such as "click"
.请注意,如果您仍想处理诸如"click"
事件,则上述解决方案不起作用。
Also, Apple fixes the issue in WebKit by allowing using -webkit-user-select: none;
此外,Apple 通过允许使用-webkit-user-select: none;
修复了 WebKit 中的问题-webkit-user-select: none;
to disable magnifying glass, see https://bugs.webkit.org/show_bug.cgi?id=231161要禁用放大镜,请参阅https://bugs.webkit.org/show_bug.cgi?id=231161
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.