javascript - 在某些网站上无法在注入的 contenteditable div 中键入空格
问题描述
我正在开发一个 Chrome 扩展程序,它通过 shadowDOM 将 contentEditable div 注入网站(想想页面顶部的输入字段)。但是,将内容脚本注入 YouTube 时,无法在 contentEditable 中键入空格。到目前为止,我还没有在任何其他网站上遇到过这个问题。
这可能是什么原因?
到目前为止的方法:
- 有效的是捕捉空间
keydown
事件并以
编程方式将一个插入符号位置。我想知道是否有更优雅和更精简的解决方案,而且我仍然想知道这个问题的原因是什么。
要重现,请在youtube.com上注入 contenteditable并尝试添加更多空间。
const div = document.createElement('div')
div.contentEditable = true
div.style.background = '#fff'
div.style.color = '#000'
div.style.height = '200px'
div.style.fontSize = '48px'
div.style.position = 'relative'
div.style.zIndex = '999999'
div.innerHTML = `It's not possible to add any more spaces...`
document.body.prepend(div)
解决方案
推荐阅读
- alpacajs - TypeError: $(...).getValue 不是函数
- web-services - 在不同平台上使用 Web 服务的分布式事务
- keras - 如何在进行迁移学习的同时重塑 pytorch CNN 模型的最后一层
- python - 你如何在 tkinter 中创建一个小部件的动画?
- tensorflow - Tensorflow DeepLab Colab 对图像 URL 执行 npt
- spark-ar-studio - Spark AR中有什么方法可以进行多个固定目标跟踪
- jdbc - Google Cloud - 将 Sql Server 连接到 Google Apps 脚本
- python-3.x - Pandas Dataframe - 按日期对列表元素进行排序,当日期是元素的子字符串时
- c# - C#' MVVM Observable Proxies aka Android LiveData?
- python - Python套接字编程的Web服务器不向浏览器发送信息