最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Copy the current URL into a new alert window using javascript - Stack Overflow

programmeradmin0浏览0评论

I struggled for hours to find out how to make a javascript function to copy the current URL into a new alert window. For example, when a user click "Share this page", then a new alert window appears with the URL selected in an input text box:

How can I make it done with javascript?

Thanks.

I struggled for hours to find out how to make a javascript function to copy the current URL into a new alert window. For example, when a user click "Share this page", then a new alert window appears with the URL selected in an input text box:

How can I make it done with javascript?

Thanks.

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Oct 14, 2015 at 10:31 PeterPeter 7324 gold badges10 silver badges25 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 9

As simple as this:

prompt('Please copy the following URL:', window.location);

prompt('Please copy the following URL', window.location.href)

For a better user experience you may consider allowing access to the clipboard with clipboard.js.

You can use the simple snippet code, window.location as the second param in prompt.

window.copyURL = function(){
prompt("Press [Ctrl + c] to copy the url :",window.location);
}
<button onclick="copyURL()">Copy URL </button>

发布评论

评论列表(0)

  1. 暂无评论