#鸿蒙通关秘籍#在Web组件中如何判断设备是否支持touch事件?

HarmonyOS
2024-12-02 15:41:14
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
CI风舞

需要在Web组件中添加监听touch事件的机制,以判断设备是否支持touch。

<body>
    <div>
        <div id="bodyId">
            <embed id="nativeSearch" type="native/component" width="100%" height="100%" src="view" />
        </div>
    </div>
    <script>
        let nativeEmbed = {
            nativeSearch: document.getElementById('nativeSearch'),
            events: {},
            init: function () {
                let self = this;
                self.nativeSearch.addEventListener('touchstart', self.events, false);
            }
        };
        nativeEmbed.init();
    </script>
</body>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.

在上面的代码中,通过embed标签和添加触摸事件监听判断设备支持情况。

分享
微博
QQ
微信
回复
2024-12-02 16:59:46
相关问题
如何判断Web组件是否全屏
2723浏览 • 1回复 待解决
Web如何判断是否发生重定向
1647浏览 • 1回复 待解决
Web组件如何判断网址是否加载成功
3128浏览 • 1回复 待解决