2

I'm searching for a way to get the phone number of a device using HTML 5, Javascript or something like it. Recently, I wanted to get the coordinates of the device. I could easily do that by writing something in HTML 5 like:

<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to get your coordinates:</p>
<button onclick="getLocation()">Try It</button>
<script>
var x=document.getElementById("demo");
function getLocation()
  {
  if (navigator.geolocation)
    {
    navigator.geolocation.getCurrentPosition(showPosition);
    }
  else{x.innerHTML="Geolocation is not supported by this browser.";}
  }
function showPosition(position)
  {
  x.innerHTML="Latitude: " + position.coords.latitude + 
  "<br>Longitude: " + position.coords.longitude;    
  }
</script>
</body>
</html>

Now I'm almost done with my part of the job, but the last thing I need to do is to get the phone number of the smartphone that access that website.

Is there ANY way to do this? :/ please... and thank you.

SamyCode
  • 818
  • 2
  • 10
  • 29
  • 4
    Almost definitely not. Anyway, if you do, you'll probably be violating some privacy laws for taking information like a phone number without user permission or knowledge. – Linuxios Jan 21 '14 at 22:40
  • 2
    `Is there ANY way to do this?` Yes; prompt the user to input their number. – admdrew Jan 21 '14 at 22:41
  • from a JS perspective, data and voice flow though different pipes that's aren't connected or even aware of eachother. – dandavis Jan 21 '14 at 22:49
  • Does this answer your question? [How can I get the device's phone number through JavaScript in Android?](https://stackoverflow.com/questions/4003339/how-can-i-get-the-devices-phone-number-through-javascript-in-android) – Didier L Mar 09 '20 at 09:35

3 Answers3

5

There is no reliable way to get a phone number with JavaScript without prompting the user. That is, it cannot be retrieved automatically using a browser API.

It is possible inside of certain Android / iPhone application views. See discussions here: How can I get the device's phone number through JavaScript in Android?. And here: Getting the local iPhone number through SDK

As mentioned in comments, this is not a good thing to do in general (privacy, etc.). Definitely prompt the user for input if the phone number is needed.

Community
  • 1
  • 1
ebuat3989
  • 4,941
  • 3
  • 24
  • 17
  • `this is not a good thing to do in general (privacy, etc.)`. disagree… In many european countries you need to be able to have coordinates that can be used to physically identify the user so he/she can get arrested in case of racial hate speech on your web service. The phone number is a stronger warenty than e‑mail. – user2284570 May 28 '16 at 18:54
  • 3
    @user2284570 No, you don't. That's complete and utter nonsense -- no such laws exist. In fact, EU privacy regulations would likely make such practices illegal. –  Apr 28 '17 at 16:49
  • @duskwuff unless he/she explicitly agreed, and there are still huge restrictions. – user2284570 Apr 28 '17 at 16:53
  • 1
    "That is, it cannot be retrieved automatically using a browser API." There's any official documentation that states that behavior? – Paulo R. F. Amorim Oct 08 '20 at 13:30
1

i think it is possible. the network providers at my country(kenya)- www.safaricom.com .do seam to some how get your mobile phone number when you open there website. even when using a modem you can buy data online without having to input your number cause you get it already printed out. i tried using wi-fi tethering from my android phone en then opened there site en they could still get my mobile phone number. try reading the source code of the site maybe it might help. maybe it has to do with much more than basic js and php. i tried changing the number using the developer tools but it doesn,t work.

pickman
  • 31
  • 1
0

also I think that is possible, in my country (in Italy) when I go on site of iliad they know my phone number, I also tried it in incognito mode

FarukT
  • 1,400
  • 10
  • 22