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 html code:
<div style="height:1000px; width:100px"></div>
<br />
<a href="#" onclick="return false">click me</a>
When click in moblie devices' safari, it goes back to the top of the page...
Step to view full URL of links in Safari on iPhone and iPad:Press and hold a link on the webpage until a menu pops up on the screen, and then you can check its full URL on the menu, as shown in the following picture.
Set up iCloud Safari on Mac On your Mac, choose Apple menu > System Preferences, click Apple ID, then select iCloud in the sidebar > Select and check Safari. Then in the Safari app on your Mac, you can choose History and click Show All History. All browsing history is synced on your Mac.
I had the same problem. It turns out that it is a bug in the iOS 5 version of Safari. Doesn't happen in newer or older versions, or any other browser or platform.
I resolved it by adding preventDefault
to the onclick event handler, in addition to the existing return false
, like so:
<a href="#" onclick="event.preventDefault(); return false;">click me</a>
Not ideal, but it does solve the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With