Omnipotent JS copy button

Source: Internet
Author: User
This is a JS copy button that imitates Youku's video sharing and is compatible with various browsers.

<! -- Copy button JS --> <SCRIPT> function copytoclipboard (txt) {If (window. clipboardData) {window. clipboardData. cleardata (); window. clipboardData. setdata ("text", document. getelementbyid (txt ). value);} else if (navigator. useragent. indexof ("Opera ")! =-1) {// do nothing} else if (window. netscape) {try {Netscape. security. privilegemanager. enableprivilege ("universalxpconnect");} catch (e) {alert ("rejected by the browser! \ N enter 'about: config' in the address bar of the browser, press enter \ n, and then 'signed. applets. codebase_principal_support 'is set to 'true' ");} var clip = components. classes ['@ mozilla.org/widget/clipboard1_1').createinstance (components. interfaces. nsiclipboard); If (! Clip) return; var trans = components. classes ['@ mozilla.org/widget/transferable1_1'assist.createinstance (components. Interfaces. nsitransferable); If (! Trans) return; trans. adddataflavor ('text/Unicode '); var STR = new object (); var Len = new object (); var STR = components. classes ["@ mozilla.org/supports-string1_1"]. createinstance (components. interfaces. nsisupportsstring); var copytext = txt; Str. data = copytext; trans. settransferdata ("text/Unicode", STR, copytext. length * 2); var clipid = components. interfaces. nsiclipboard; If (! Clip) return false; clip. setdata (trans, null, clipid. kglobalclipboard);} alert ("You have successfully copied this address. Please paste it and recommend it to your friends! ") ;}</SCRIPT>

**************************************** **************************************** *************

Usage:

<! -- Share dialog box --> <Div class = "share"> <Div class = "sharetop"> </div> <Div class = "sharebord"> <H4> share with the website friend </H4> <Div class = "item"> <SPAN class = "label"> video address: </span> <input type = "text" id = "link1" value = "http://www.moredoo.com/10002"/> <button onclick = "javascript: copytoclipboard ('link1 '); "> copy </button> </div> <H4> paste the video to a blog or BBS </H4> <Div class =" item "> <SPAN class =" label "> flash Address: </span> <input type = "text" id = "link2" value = "http://www.moredoo.com/10002"/> <button onclick = "javascript: copytoclipboard ('link2 '); "> copy </button> </div> <Div class =" item "> <SPAN class =" label "> HTML code: </span> <input id = "link3" type = "text" value = '<embed src = "http://www.moredoo.com/10002" allowfullscreen = "true" Quality = "high" width = "480 "Height =" 400 "align =" Middle "allowScriptAccess =" always "type =" application/X-Shockwave-flash "> </embed> '/> <button onclick =" javascript: copytoclipboard ('link3'); "> copy </button> </div> <Div class =" sharebutom ">

The effect is as follows:

Effect:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.