文章源自今夕何夕兮-https://www.ginc.site/building-and-development733.html
方法1:使用sweetalert.js库
复制下面的代码放到function文件中即可:文章源自今夕何夕兮-https://www.ginc.site/building-and-development733.html
//复制成功提示
function copyright_tips() {
echo '<link rel="stylesheet" type="text/css" rel="external nofollow" target="_blank" href="https://lyboy.oss-accelerate.aliyuncs.com/wordpress/css/sweetalert.min%20.css" >';
echo '<script src="https://lyboy.oss-accelerate.aliyuncs.com/wordpress/js/sweetalert.min.js"></script>';
echo '<script>document.body.oncopy = function() { swal("复制成功!", "转载请务必保留原文链接,申明来源,谢谢合作!!","success");};</script>';
}
add_action( 'wp_footer', 'copyright_tips', 100 );
注意:代码中 sweetalert.min.css 文件跟 sweetalert.min.js 提供文件下载,可以下载后上传到自己的对象存储或网站根目录,再修改链接。文章源自今夕何夕兮-https://www.ginc.site/building-and-development733.html
效果图:
文章源自今夕何夕兮-https://www.ginc.site/building-and-development733.html
方法2:使用复制监听,右上角弹窗
1、在header.php文件中引入js和css。文章源自今夕何夕兮-https://www.ginc.site/building-and-development733.html
<script src="https://lyboy.oss-accelerate.aliyuncs.com/wordpress/js/toastr.js"></script> <link rel="stylesheet" href="https://lyboy.oss-accelerate.aliyuncs.com/wordpress/css/toastr.css" />
这里提供js跟css文件下载:文章源自今夕何夕兮-https://www.ginc.site/building-and-development733.html
注意:如果网站没有引入jquery则需要额外引入文章源自今夕何夕兮-https://www.ginc.site/building-and-development733.html
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
2、添加复制监听函数文章源自今夕何夕兮-https://www.ginc.site/building-and-development733.html
在header.php中添加以下代码:文章源自今夕何夕兮-https://www.ginc.site/building-and-development733.html
<script type="text/javascript">
function copy_remind(){
toastr.success("撰文不易,请保留出处,谢谢!", "复制成功!");
clear_toastr(1600);
// 动态设置消息提示时间
function clear_toastr(time){
setTimeout(
function(){
toastr.clear();
}, time);
}
}
document.addEventListener("copy",function(e){
if(window.getSelection(0).toString()){
copy_remind(); //若所选文本不为空则显示
}
else{
toastr.info("啊噢...你没还没选择文字呢!", "复制提示");
}
});
</script>
效果图:
文章源自今夕何夕兮-https://www.ginc.site/building-and-development733.html
转载请注明来自:今夕何夕兮
除特别声明外,本站内容遵循 CC-BY-NC-SA4.0 协议授权。部分资源收集于网络,只做学习和交流使用,版权归原作者所有。


中国–浙江–杭州 1F
方法二资料原文:https://www.szfx.top/network-tech/copy-popupwindow.html
中国–北京–北京 2F
效果不错!