Thursday, April 19, 2012

In moblie devices' safari, <a href="#" onclick="return false"> doesn't work, why?

In moblie devices' safari, like iphone or ipad, <a href="#" onclick="return false"> doesn't prevent default behaviour, the page was still redirected to '#', why...?
Like these code:



<a href="#" onclick="return false" id="test_a">click me</a>

var elem = document.getElementById('test_a');
if (elem.addEventListener) {
elem.addEventListener('click', function() {
alert('clicked');
}, false);
} else {
elem.attachEvent('onclick', function() {
alert('clicked');
});
}?




No comments:

Post a Comment