复制
html代码
<span class="hleft" onclick="copyLink('内容asdf','text')">复制链接</span>
<textarea id="text">待复制的内容</textarea>
js代码
function copyLink (s, id) { //复制到剪切板
if (document.execCommand) {
var e = document.getElementById(id);
e.select();
e.setSelectionRange(0, e.value.length);
document.execCommand("Copy");
return true;
}
if (window.clipboardData) {
window.clipboardData.setData("Text", s);
return true;
}
return false;
}
自动点击事件实现页面自动跳转
html代码
<a id="link" href="http://baidu.com"></a>
window.onload = function() {
var link = document.getElementById('link')
link.dispatchEvent(customClickEvent())
}
function customClickEvent() {
var c;
if (window.CustomEvent) {
c = new window.CustomEvent("click", {
canBubble: true,
cancelable: true
})
} else {
c = document.createEvent("Event");
c.initEvent("click", true, true)
}
return c;
}
网友评论