简体   繁体   中英

Re prompt for Camera permission in JS after initial denial

I want to re-prompt for camera permission if the user denies it the first time.

Code:

navigator.mediaDevices.getUserMedia({video: true, audio: false}).then(function(){
      document.getElementById("submitbutton").style.display="inline"; 
  }).catch(function(err){alert("Please provide consent.");location.reload();});

The above code reloads the page after I deny the permission the first time. But after reload, it does not prompt for permission rather it again goes into the.catch block

I believe this is happening because the browser stores the denied promise the first time itself and check the same promise on page reload.

Is there any way I can force the permission prompt to appear again?

No, you can't.

This is a deliberate decision on the part of the browser designers to prevent websites from becoming annoying with their (potentially invasive) permission requests. Once a user has rejected the permission request, they have to dig into their browser settings to re-allow requests from that domain. Read more here.

A trick that has become popular, though, is to not ask for permission until after the user has done something that indicates they actually want the feature indicated.

So, for example, you may want your user flow to go something like:

If you're going to invade the user's privacy, it will go best for you if you explain why you're doing it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM