copy_link.html 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>推广链接</title>
  6. <meta name="renderer" content="webkit">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  8. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  9. <link rel="stylesheet" href="../../component/pear/css/pear.css"/>
  10. <link rel="stylesheet" href="../../admin/css/other/console1.css?v=v2.0.3"/>
  11. <link rel="stylesheet" href="../../public/css/sponsored_links/sponsored_links.css?v=v2.0.3"/>
  12. <style>
  13. .pear-btn-primary {
  14. width: 100%;
  15. margin-top: 10px;
  16. }
  17. </style>
  18. </head>
  19. <body class="pear-container">
  20. <input type="text" id="link" required lay-verify="required" placeholder="" readonly autocomplete="off" class="layui-input">
  21. <textarea hidden id="taCode" rows="8" style="resize: none"></textarea>
  22. <button id="btCopy" type="button" class="pear-btn pear-btn-primary">复制链接</button>
  23. <script src="../../component/layui/layui.js"></script>
  24. <script src="../../component/pear/pear.js"></script>
  25. <script src="../../app/app.js?v=v2.0.3"></script>
  26. <script src="../../config/config.js?v=v2.0.3"></script>
  27. <script src="../../public/config/login.js?v=v2.0.3"></script>
  28. <script>
  29. layui.use(['jquery','layer',], function () {
  30. let $ = layui.jquery;
  31. let layer = layui.layer;
  32. let url = window.location.search;
  33. let link = url.split('?|||')[1];
  34. $('#taCode').text(link);
  35. $('#link').val(link);
  36. // 复制文本内容到剪切板
  37. $("#btCopy").click(function() {
  38. copyText($("#taCode").val());
  39. layer.msg('复制链接成功!快去分享吧!')
  40. });
  41. function copyText(obj) {
  42. if (!obj) {
  43. return false;
  44. }
  45. var text;
  46. if (typeof(obj) == 'object') {
  47. if (obj.nodeType) { // DOM node
  48. obj = $(obj); // to jQuery object
  49. }
  50. try {
  51. text = obj.text();
  52. if (!text) { // Maybe <textarea />
  53. text = obj.val();
  54. }
  55. } catch (err) { // as JSON
  56. text = JSON.stringify(obj);
  57. }
  58. } else {
  59. text = obj;
  60. }
  61. //var $temp = $('<input>'); // Line feed is not supported
  62. var $temp = $('<textarea>');
  63. $('body').append($temp);
  64. $temp.val(text).select();
  65. var res = document.execCommand('copy');
  66. $temp.remove();
  67. return res;
  68. }
  69. });
  70. </script>
  71. </body>
  72. </html>