Click-copy Code implemented in javascript

Source: Internet
Author: User

<Title> title </title>
<Input type = "button" name = "Submit" onClick = 'copytoclipboard () 'value = "copy the topic address and send it to friends on QQ/MSN">
<Script language = "javascript">
Function copyToClipBoard (){
Var clipBoardContent = "";
ClipBoardContent + = document. title;
ClipBoardContent + = "";
ClipBoardContent + = this. location. href;
Window. clipboardData. setData ("Text", clipBoardContent );
Alert ("Copied successfully, paste it on your QQ/MSN and recommend it to your friends ");
}
</Script>

<Script>
Function oCopy (obj ){
Obj. select ();
Js = obj. createTextRange ();
Js.exe cCommand ("Copy ")
}
</Script>
<Input onclick = "oCopy (this)" value = "content to copy! ">

<Script language = "javascript">
Function CopyUrl (target ){
Target. value = myimg. value;
Target. select ();
Js = myimg. createTextRange ();
Js.exe cCommand ("Copy ");
}
Function AddImg (target ){
Target. value = "[IMG]" + myimg. value + "[/img]"; (Note: Remove spaces after/in [/img)
Target. select ();
Js = target. createTextRange ();
Js.exe cCommand ("Copy ");
}
</Script>
<Input name = myimg type = hidden id = myimg value = "http://www.jb51.net"/>
<Input name = imgurl type = text size = 32 value = "http://www.jb51.net"/>
<Input type = button value = "Click here to copy the address of this site" onclick = "CopyUrl (imgurl);"/>
<P> if you like this site, recommend it to your friends! </P>

<Script type = "text/javascript">
Function copyText (obj)
{
Var rng = document. body. createTextRange ();
Rng. moveToElementText (obj );
Rng. scrollIntoView ();
Rng. select ();
Rng.exe cCommand ("Copy ");
Rng. collapse (false );}
</Script>
The following is a code snippet:
Copy codeThe Code is as follows:
<Span id = "tbid"> http://www.jb51.net </span>
[<A href = "#" onclick = "copyText (document. all. tbid)"> click to copy </a>] <br/>
<Span id = "tbid2"> http://www.jb51.net </span>
[<A href = "#" onclick = "copyText (document. all. tbid2)"> click to copy </a>] <br/>

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.