javascript - 使用 JavaScript 在移动网站中自动对焦地址栏
问题描述
是否可以使用 JavaScript 自动聚焦移动网站中的地址栏?(背景:我想在 Android 的 Chrome 浏览器上打开一个我的网站,并让地址栏专注于能够输入它)
我找到了这个代码示例,但它仅适用于网站中的输入字段:
Homepage: <input type="url" id="myURL" value="http://www.google.com">
<p>Click the buttons below to give focus and/or remove focus from the URL field.</p>
<button type="button" onclick="getFocus()">Get focus</button>
<button type="button" onclick="loseFocus()">Lose focus</button>
<p><strong>Note:</strong> elements with type="url" are not supported in IE 9 (and earlier), or Safari.</p>
<script>
function getFocus() {
document.getElementById("myURL").focus();
}
function loseFocus() {
document.getElementById("myURL").blur();
}
</script>
解决方案
您可以通过 js 或其他首选编程语言将以下快捷方式发送到浏览器以关注地址栏:
Ctrl+l
推荐阅读
- sql-server - SQL Server 存储过程作为输入错误
- julia - 如何使用 Julia 处理 CSV?
- javascript - 在使用 React-Hooks 时,我在 React 代码中获得了无限的重新渲染。我该如何解决这个问题?
- python - python-freeopcua 中的 Pub-Sub
- memory-leaks - OpenLayers 6 setTileLoadFunction() 记录示例使用 URL.createObjectURL(data),需要调用 revokeObjectURL() 以避免内存泄漏
- mysql - 在 mysql 中创建整数序列的最优雅的方法是什么?
- bash - 如何从 bash 脚本启动 docker 容器?
- jmeter - 无法从 Concourse CI 运行 Taurus.yml 文件
- android - android-10.0.0_r39 的 build_image.py 中的 Android AOSP 构建失败
- r - 如何在 R 中完成一个变量在其因子水平上的相关性,按日期匹配