You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Google Earth Pro的Placemark中实现剪贴板复制按钮?

解决Google Earth Pro Placemark中复制按钮失效的问题

Google Earth Pro的内置HTML渲染环境不支持现代的navigator.clipboardAPI,这是导致你原有代码点击无响应的核心原因。可以改用兼容性更好的document.execCommand('copy')方法实现复制功能,同时调整HTML结构适配Placemark的限制:

可行代码示例

<input type="text" value="House number is 257641" id="myInput" style="width:100%;">
<button onclick="myFunction()">Copy text</button>

<script>
function myFunction() {
  var copyText = document.getElementById("myInput");
  // 选中输入框内容
  copyText.select();
  // 兼容旧环境的复制命令
  document.execCommand('copy');
  // 取消选中状态(可选优化)
  window.getSelection().removeAllRanges();
  // 提示复制成功(Google Earth Pro支持alert弹窗)
  alert("Copied the text: " + copyText.value);
}
</script>

使用注意事项

  • 直接将上述代码粘贴到Placemark的描述框中即可,不需要保留外层的<!DOCTYPE html>、<html>、<body>标签
  • 若不想显示输入框,可给input添加样式style="position:absolute;left:-9999px;"将其隐藏,复制逻辑不受影响
  • 部分旧版本Google Earth Pro可能限制脚本执行,建议升级到最新版本测试

内容的提问来源于stack exchange,提问作者Raffa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 18:05:19