5

How can i trigger this modal on javascript button click

enter image description here

Hakan
  • 835
  • 1
  • 12
  • 15
  • @Hakan just a note – it's `navigator.mediaDevices.getUserMedia` now (used to be just `navigator.getUserMedia`) – helb Jun 28 '18 at 08:33

1 Answers1

9

You need to get the permission using the navigator object.

navigator.mediaDevices.getUserMedia({ audio: true })
      .then(function(stream) {
        console.log('You let me use your mic!')
      })
      .catch(function(err) {
        console.log('No mic for you!')
      });

Also you need to run it on HTTPS and on a website instead of using IP addresses

Saransh Kataria
  • 1,329
  • 9
  • 16
  • It shows in console but how can we show modal to user . – user3717278 Mar 19 '20 at 12:32
  • you need to replace the console.log logic with whatever you use to show modals – Saransh Kataria Mar 21 '20 at 17:31
  • @SaranshKataria : I have some javascript code in my flask webserver, when I run it on localhost, I can record easily. But when the code is on the server, when I press the button for **Record**, I don't see any recording start, do I need to run it on `HTTPS` instead of `HTTP` and on a website? Isn't `HTTPS` more about being secure? – aspiring1 May 15 '20 at 11:45
  • 1
    @aspiring1 since media and camera are powerful features, the web standards enforce them to work only on HTTPS websites. You can read more about it on https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia – Saransh Kataria May 16 '20 at 19:38
  • The popup in my chrome browser has Allow and Block buttons interchanged. Any browser setting for that? – CodeZila Feb 02 '21 at 14:17