Home  >  Article  >  Web Front-end  >  JavaScript implements copying the current URL by clicking a button_javascript skills

JavaScript implements copying the current URL by clicking a button_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:25:581567browse

Click the button to copy the current URL:

A large number of websites have this function. When you click a button, you can copy the address of the current page. This can facilitate website users to store links and facilitate website promotion. Let’s introduce it with examples below. How to implement this feature:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.jb51.net/" />
<title>脚本之家</title>
</head>
<body>
<input type="button" name="button" value="复制本页标题和网址,推荐给您的好友"><br><br>
<script type="text/javascript">
function softwhy() {
 var clipBoardContent = "";
 clipBoardContent += document.title;
 clipBoardContent += "\n";
 clipBoardContent += this.location.href;
 window.clipboardData.setData("Text", clipBoardContent);
 alert("脚本之家提示:复制成功!");
}
</script>
</body>
</html> 

The above code can copy the current link when clicking the button, but unfortunately only IE browser supports this function. The above code is also very simple. If you have any questions that you don’t understand, please feel free to ask. Thank you. !

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn