views:

536

answers:

2

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.

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

any help is appreciated

+5  A: 

Try handling the selectstart event and returning false.

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

SLaks
thanks, works great!
pop850
dont have enough reputation
pop850
now you do :) good question and good answer.
Jonathan Fingland
A: 

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:

$.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'); 
                }); 
        } 
});
orangechicken