简体   繁体   中英

How to copy and paste the web page into email using javascript/jquery

I am working on some stuff where I have to need copy the web page and when I copied that page I will be able to paste that web page in email and can send as it is to someone. The below code only works with to copy the text or html tags but I need to copy whole page as it is. If there is some way let me know.

<p id="p1">P1: I am paragraph 1</p>
<p id="p2">P2: I am a second paragraph</p>
<button onclick="copyToClipboard('p1')">Copy P1</button>
<button onclick="copyToClipboard('p2')">Copy P2</button>



function copyToClipboard(elementId) {

 // Create a "hidden" input
 var aux = document.createElement("input");

 // Assign it the value of the specified element
 aux.setAttribute("value", document.getElementById(elementId).innerHTML);

 // Append it to the body
 document.body.appendChild(aux);

 // Highlight its content
 aux.select();

 // Copy the highlighted text
 document.execCommand("copy");

 // Remove it from the body
 document.body.removeChild(aux);

}

如果要获取完整的html文档,可以在下面使用

**document.documentElement.outerHTML**

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM