Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button not working on Mobile Devices but works on PC bootstrap

I created a bootstrap button that has a link inside. Which looks like this:

enter image description here

When you hover on it:

enter image description here

This is the code inside the button:

 <div class="s-8"><button type="button" onClick="javascript:location.href = 'administration.php';">Administration</button></div>

The logout button:

<div class="s-4"><button type="button" onClick="javascript:location.href = 'logout.php';">Logout</button></div>

This button works fine on the PC(IE, SAFARI, FireFox, Chrome, Opera) browser(takes me to the administration page, but it doesn't work on the Mobile devices.

I did the same thing for the logout button, and it works fine on PC and Mobile Devices. I am now puzzled.

like image 483
kya Avatar asked Mar 11 '15 12:03

kya


3 Answers

The issue may be that you're using the onClick event which won't register on a mobile device (as you don't click - you tap).

This answer explains how to use the "touchstart" event which will work on a mobile.

https://stackoverflow.com/a/22015946/2619909

like image 175
Git Paul Avatar answered Oct 09 '22 01:10

Git Paul


unfortunately neither setting cursor:pointer; nor adding a touchstart event listener

$(document).ready(function() {
  $('#button_id').on('click touchstart', function() {
    window.location.href = "/url";
  });
});

as @noa-dev and @GitPauls suggested worked for me. for reference I tested on my phone7 (ios11.4 and safari)

working solution: I set the z-index of the button to a large positive number and the button now works.

#button_id{
  z-index: 99;
}

solution found thanks to Daniel Acree https://foundation.zurb.com/forum/posts/3258-buttons-not-clickable-on-iphone. I don't know if this generalizes to all iphone/mobile devices.

like image 36
jstm Avatar answered Oct 09 '22 00:10

jstm


I know this might be a weird answer. But in some cases mobile clickevents dont work unless you put the style: cursor:pointer; to your button.

Mobile clickEvents are handled very differently, the first "click" or "tap" might be interpreted as a HOVER instead of the click which you are looking for.

So try setting the CSS style of the button to : cursor:pointer;

like image 4
noa-dev Avatar answered Oct 09 '22 01:10

noa-dev