【问题标题】:How to control the size and position of the window used by navigator.bluetooth.requestDevice?如何控制 navigator.bluetooth.requestDevice 使用的窗口的大小和位置?
【发布时间】:2017-08-17 20:53:12
【问题描述】:

参考本期:How to make the Web Bluetooth Pair button work when run as chrome app

在我的测试中,调用 navigator.bluetooth.requestDevice 时弹出的窗口非常大,完全覆盖了调用它的 html 窗口,并且包含 Pair 和 Cancel 按钮的窗口底部已关闭屏幕底部,因此不可见。

requestDevice窗口是否可以控制和定位?

<html>
  <head>
   <script type="text/javascript" src="bluetoothle.js"></script> 
   <script type="text/javascript" src="popup.js"></script>
  </head>
  <body>
    <h1>Hello Bluetooth</h1>
    <h2>Device Discovery</h2>
    <button id="btn_discover">Discover Devices</button>
    <div id="devices"></div>
  </body>
</html>

navigator.bluetooth.requestDevice(options)
  .then(device => {
    console.log('> Name:             ' + device.name);
    console.log('> Id:               ' + device.id);
    console.log('> Connected:        ' + device.gatt.connected);
    bluetoothle.selected_device = device;
    console.log(bluetoothle.selected_device);
  })
  .catch(error => {
    console.log('ERROR: '+ error);
  });

【问题讨论】:

    标签: web-bluetooth


    【解决方案1】:

    不,无法控制 requestDevice() 打开的设备选择器窗口的大小。它将使用固定的最大尺寸。 (在这里写作时,我手头没有这些尺寸。)chrome.app.window 可以最大化打开以在短期内解决这个问题。

    (此外,虽然开发 chrome 应用程序或将网络蓝牙改装成以前的应用程序可能是有原因的,但如果您还没有看到 Chrome 应用程序是 deprecated on Windows, macOS, Linux,您应该阅读公告。)

    【讨论】:

      【解决方案2】:

      【讨论】:

      • 是的,我明白了。谢谢。如果您可以控制设备选择器窗口的大小和位置,那就太好了。不过无论如何都不是关键问题。
      猜你喜欢
      • 2011-03-20
      • 1970-01-01
      • 2020-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-22
      相关资源
      最近更新 更多