1. انقر فوق الزر لنسخ المحتوى في مربع النص
<script type = "text/javaScript"> function copyurl2 () {var url2 = document.getElementById ("biao1") ؛ url2.select () ؛ // حدد Object document.execCommand ("Copy") ؛ // قم بتنفيذ تنبيه أمر نسخ المتصفح ("نسخ ، يمكنك لصق.") ؛} </script> <textarea cols = "20" rows = "10" id = "biao1"2. انسخ عنوان الموضوع وعنوان عنوان URL ونقله إلى الأصدقاء على QQ/MSN
<! doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3 xmlns = "http://www.w3.org/1999/xhtml"> <head> <meta http-equiv = "content-type" content = "text/html ؛ charset = gb2312"/> <title> js copy code code </head> <body> <p> onClick = 'copytoclipboard ()' 'value = "انسخ عنوان الموضوع وعنوان عنوان URL ونقله إلى الأصدقاء على QQ/MSN"> <script language = "javaScript"> وظيفة copytoclipboard () {var clipboardcontent = "" ؛ clipboardcontent+= document.title ؛ clipboardcontent+= "" ؛ clipboardcontent+= this.location.href ؛ window.clipboarddata.setdata ("text" ، clipboardcontent) ؛ ALERT ("copy بنجاح ، يرجى تعبئته على QQ/msn الخاص بك3. نسخ عنوان URL مباشرة
<type type = "button" name = "anniu2" onClick = 'copyUrl ()' value = "copy url address"> <script language = "javaScript"> function copyurl () {var clipboardcontent = th this.location.href ؛ window.clipboarddata.setdata ("text" ، clipboardcontent) ؛4. عند النقر فوق مربع النص ، انسخ المحتويات في مربع النص.
<input onClick = "ocopy (this)" value = "hello. to copy content!
5. انسخ المحتوى في مربع النص أو إخفاء الحقل
<script language = "javaScript"> function copyurl (target) {target.value = myimg.value ؛ target.select () ؛ JS = myimg.createTextRange () ؛ JS.ExecCommand ("copy") ؛ ALERT ("Copy Success!") ؛} الوظيفة addimg (target) {target.value = "[img]"+myimg.value+"[/ img] ؛ JS.ExecCommand ("نسخ") ؛ تنبيه ("نسخ ناجح!") ؛} </script>6. انسخ المحتويات في علامة الامتداد
<script type = "text/javaScript"> </script> <br/> <br/> <script type = "text/javaScript"> function copyText (obj) {var rng = document.body.createtextrange () ؛ rng.movetoElementText (obj) ؛ rng.scrollintoview () ؛ rng.select () ؛ rng.execcommand ("نسخة") ؛ rng.collapse (false) ؛ تنبيه ("نسخ النجاح!") ؛} </"7. متصفح متوافق مع copytoclipboard ("نسخ محتوى")
دالة copytoclipboard (txt) {if (window.clipboarddata) {window.clipboarddata.cleardata () ؛ clipboarddata.setData ("text" ، txt) ؛ تنبيه ("نسخ بنجاح!") ؛ } آخر إذا (navigator.useragent.indexof ("Opera")! = -1) {window.location = txt ؛ } آخر إذا (window.netscape) {try {netscape.security.privileGemanager.EnablePrivilege ("UniversalxpConnect") ؛ } catch (e) {Alert ("تم رفضها بواسطة المتصفح! } var clip = components.classes ['@mozilla.org/widget/clipboard؛1'/10.createinstance(components.interfaces.nsiclipboard) ؛ إذا (! مقطع) العودة ؛ var trans = components.classes ['@mozilla.org/widget/transferable ؛1'/10.createinstance(components.interfaces.nsitransferable) ؛ إذا (! مقطع) العودة ؛ var trans = components.classes ['@mozilla.org/widget/transferable ؛1'/10.createinstance(components.interfaces.nsitransferable) ؛ إذا (! trans) العودة ؛ trans.adddataflavor ("text/unicode") ؛ var str = new Object () ؛ var len = new Object () ؛ var str = components.classes ["@mozilla.org/supports-tring ؛1"/201.createinstance(components.Interfaces.nsisupportsString) ؛ var copyText = txt ؛ str.data = copyText ؛ trans.settransferdata ("text/unicode" ، str ، copyright.length * 2) ؛ var clipid = components.Interfaces.nsiclipboard ؛ إذا (! مقطع) العودة كاذبة ؛ clip.setData (trans ، null ، clipid.kglobalclipboard) ؛ تنبيه ("نسخ بنجاح!") ؛ }}8. متوافق مع رموز النسخ للمتصفحات الرئيسية (جنبا إلى جنب مع zeroclipboard.js)
<html> <head> <title> اختبار الحافظة الصفر </title> <script type = "text/javaScript" src = "zeroclipboard.js"> </script> <script language = "javaScript"> var clip = null ؛ الدالة $ (id) {return document.getElementById (id) ؛ } function init () {clip = new Zeroclipboard.client () ؛ Clip.SethandCursor (True) ؛ clip.addeventListener ('mouseover' ، function (client) {// reported the text on mouse over clip.settext ($ ('fe_text'). value) ؛}) ؛ clip.addeventListener ('complete' ، function (client ، text) {// debugstr ("text proced to clipboard:" + text) ؛ Alert ("تم نسخ هذا العنوان ، يمكنك لصقه باستخدام Ctrl + v.") ؛}) ؛ clip.glue ('clip_button' ، 'clip_container') ؛ } </script> </head> <body onload = "init ()"> <input id = "fe_text" cols = 50 rows = 5 value = copy content text1> <span id = "clip_container"> <span id = "clip_button"> <b> copy </b> </span> </span>