Js copies webpage content and is compatible with the code of mainstream browsers

Source: Internet
Author: User

Js copies webpage content and is compatible with the code of mainstream browsers

There are a lot of methods for js to copy webpage content, but there is not much code to be compatible with various browsers. Below is a good method for you to try it.

You need to make a js click to copy the current webpage url. The following method is used, but it can only be used normally in IE.

 

The method is as follows:

The Code is as follows:

Function copyURL (){

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 ");

}

 

------------------------- Separation line ---------------------------

 

Find a flash on the Internet

ZClip

 

ZClip

The zClip plugin is compatible with various browsers.

 

The method is simple. You only need to import a js file and a swf file.

 

The usage is as follows:

 

Import the required documents first:

The Code is as follows:

<Script type = "text/javascript" src = "js/jquery. js"> </script>

<Script type = "text/javascript" src = "js/jquery. zclip. js"> </script>

 

$ (Document). ready (function (){

$ ('A # copy-description'). zclip ({

Path: 'js/ZeroClipboard.swf ',

Copy: $ ('P # description'). text ()

});

 

// The link with ID "copy-description" will copy

// The text of the paragraph with ID "description"

 

$ ('A # copy-dynamic '). zclip ({

Path: 'js/ZeroClipboard.swf ',

Copy: function () {return $ ('input # dynamic '). val ();}

});

 

// The link with ID "copy-dynamic" will copy the current value

// Of a dynamically changing input with the ID "dynamic"

 

});

 

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.