防止复制某些HTML元素 [英] Prevent certain HTML elements from being copied
问题描述
我不完全确定如何去研究这个想法。我确定已经完成了,但我有一个问题阐述它为有效的Google搜索。
I'm not entirely sure how to go about researching this idea. I'm sure it's been done, but I'm having an issue articulating it for an effective Google search.
我有一个结果页,可以选择下载结果到csv。但我想,有时候,用户宁愿只是复制和粘贴在页面上的可见结果。如何获得它,所以当他们复制/粘贴,它只显示结果,而不是标题。
I have a results page that has the option to download the results to a csv. But I imagine there being times when a user would rather just copy and paste the visible results on the page. How can I get it so when they copy/paste, it only displays the results and not the headings.
<h1>results #1</h1>
<p>here are all of your awesome results</p>
<p>here are all of your awesome results</p>
<span> showing 2 of 2 </span>
所以在我的示例代码中,他们只会复制< p&
元素&不是< h1>
或< span>
。
So in my example code, they would copy just the <p>
elements & not the <h1>
or <span>
.
我认为这将是一个javascript / jquery解决方案,我很好。但不是真的甚至确定在哪里开始它。
I assume it'll be a javascript/jquery solution, which I'm fine with. But not really even sure where to start with it. Can this be reasonably accomplished?
推荐答案
您可以使用 user-select
属性, code>< h1> 和< span>
h1, span {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
这篇关于防止复制某些HTML元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!