【发布时间】:2016-09-30 12:03:03
【问题描述】:
我正在运行以下 Coffescript 代码将某些数据复制到用户剪贴板。
ready = ->
copyEmailBtn = document.querySelector('.clipboard-copy')
copyEmailBtn.addEventListener 'click', (event) ->
targetClass = document.querySelector('.clipboard-copy').dataset.targetClass
target = document.querySelector(targetClass)
range = document.createRange()
range.selectNode target
window.getSelection().addRange range
try
document.execCommand('copy')
catch err
console.log 'Oops, unable to copy'
window.getSelection().removeAllRanges()
return
if $('.clipboard-copy').length > 0
$(document).ready(ready)
$(document).on('page:load', ready)
When I click the related button to start the copy process chrome throws the following error
问题是我无法追踪它,因为它只发生在四分之一的尝试中。
复制按钮按预期工作,其他 3 次输出 4 次,但无论何时发生此错误,它都不会复制文本。
我没有尝试任何其他浏览器,因为我们的应用无法在任何其他浏览器中运行,而且不应该这样做。
以前有人处理过这个错误吗?
我尝试了以下建议,您可以从代码中看到 Discontiguous selection is not supported
关于此错误的所有其他报告都表示它不应该影响功能,更像是一个详细的警告。
【问题讨论】:
标签: ruby-on-rails google-chrome coffeescript ruby-on-rails-3.2