如何禁用MobileSafari自动选择?

时间:2022-08-24 09:15:03

my webapp requires users to tap and hold on an element for a game action,
but iPhone automatically "selects" the area which is confusing to the user.

我的webapp需要用户点击并保持一个游戏动作的元素,但是iPhone会自动“选择”用户感到困惑的区域。

anyone know what html elements prevent selection, or if javascript can block selection?

谁知道什么是html元素阻止选择,或者如果javascript可以阻止选择?

any help is appreciated

任何帮助都是赞赏

2 个解决方案

#1


34  

Try handling the selectstart event and returning false.

尝试处理selectstart事件并返回false。

Try applying the CSS rule, -webkit-user-select: none;

尝试应用CSS规则-webkit-user-select: none;

#2


13  

SLaks answer is obviously right - I just want to extend it a bit for future viewers. If you're using jQuery, here's a useful extension method that disables selection in various browsers:

SLaks的答案显然是正确的——我只是想为以后的观众们提供一些帮助。如果您正在使用jQuery,这里有一个有用的扩展方法,可以在各种浏览器中禁用选择:

$.fn.extend({ 
        disableSelection : function() { 
                this.each(function() { 
                        this.onselectstart = function() { return false; }; 
                        this.unselectable = "on"; 
                        $(this).css('-moz-user-select', 'none'); 
                        $(this).css('-webkit-user-select', 'none'); 
                }); 
        } 
});

#1


34  

Try handling the selectstart event and returning false.

尝试处理selectstart事件并返回false。

Try applying the CSS rule, -webkit-user-select: none;

尝试应用CSS规则-webkit-user-select: none;

#2


13  

SLaks answer is obviously right - I just want to extend it a bit for future viewers. If you're using jQuery, here's a useful extension method that disables selection in various browsers:

SLaks的答案显然是正确的——我只是想为以后的观众们提供一些帮助。如果您正在使用jQuery,这里有一个有用的扩展方法,可以在各种浏览器中禁用选择:

$.fn.extend({ 
        disableSelection : function() { 
                this.each(function() { 
                        this.onselectstart = function() { return false; }; 
                        this.unselectable = "on"; 
                        $(this).css('-moz-user-select', 'none'); 
                        $(this).css('-webkit-user-select', 'none'); 
                }); 
        } 
});