javascript - 如果用户拒绝摄像头访问,如何将用户重定向到单独的页面?
问题描述
我对 HTML 和 JS很陌生。如果用户拒绝相机访问但没有任何运气,我一直在尝试找到一种将用户重定向到页面的方法。有人知道怎么做吗?
解决方案
以this answer为例,您可以执行以下操作:
var facingMode = "user"; // Can be 'user' or 'environment' to access back or front camera (NEAT!)
var constraints = {
audio: false,
video: {
facingMode,
}
};
navigator.mediaDevices.getUserMedia(constraints)
.then((stream) => {
// some code
})
.catch((error) => {
// User denied the request
window.location.replace("https://example.com"); // redirect
});
推荐阅读
- angularjs - 每当输入字段更改时,如何将输入字段的值记录到控制台
- automation - 黄瓜功能插件给出“步骤'xxxxx'没有匹配的胶水代码”
- c# - 向 Microsoft Visual Studio 安装程序项目添加启动条件(检查应用程序是否正在运行)
- php - 反向显示 .tpl 循环
- python-3.x - 如何为多个页面跳转抓取具有相同 url 的网站?
- matlab - 我在 MATLAB 中计算曼哈顿距离的函数是否正确?
- html - CSS:滚动条推送我的站点标题,但不是我的 css-inner,它会导致宽度不均匀
- akka - 当发布者处理每个订阅者的背压时,Akka 流会下沉吗?
- python - pybind11:将 c++ 类(具有现有的 python 绑定)返回给 python
- yaml - Puppet 6 和模块 puppetlabs/accounts 不会以 Hiera YAML 格式创建用户帐户