如何在单击按钮时复制 URL? [英] How to copy URL on button click?

查看:28
本文介绍了如何在单击按钮时复制 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在单击按钮时复制文本区域中的当前页面 URL.不知何故,我试过了,但没有用.http://www.w3schools.com/code/tryit.asp?filename=FAF25LWITXR5

函数复制(){var Url = document.createElement("textarea");Url.innerHTML = window.location.href;复制 = Url.createTextRange();Copyed.execCommand("复制");}

<input type="button" value="Copy Url" onclick="Copy();"/><br/>粘贴:<textarea rows="1" cols="30"></textarea>

解决方案

<头><title></title><script type="text/javascript">函数复制(){//var Url = document.createElement("textarea");urlCopied.innerHTML = window.location.href;//Copied = Url.createTextRange();//Copied.execCommand("Copy");}<身体><div><input type="button" value="Copy Url" onclick="Copy();"/><br/>粘贴:<textarea id="urlCopied" rows="1" cols="30"></textarea>

</html>

I am trying to copy the current page URL in the text area on button click. Somehow I have tried but is not working. http://www.w3schools.com/code/tryit.asp?filename=FAF25LWITXR5


    function Copy() 
    {
        var Url = document.createElement("textarea");
        Url.innerHTML = window.location.href;
        Copied = Url.createTextRange();
        Copied.execCommand("Copy");
    }

<div>
 <input type="button" value="Copy Url" onclick="Copy();" />
 <br />
 Paste: <textarea rows="1" cols="30"></textarea>
</div>

解决方案

<html>
    <head>
        <title></title>
    </head>
    <script type="text/javascript">
        function Copy() 
            {
                    //var Url = document.createElement("textarea");
                    urlCopied.innerHTML = window.location.href;
                    //Copied = Url.createTextRange();
                    //Copied.execCommand("Copy");
            }
    </script>
    <body>
        <div>
            <input type="button" value="Copy Url" onclick="Copy();" />
            <br />
          
            Paste: <textarea id="urlCopied" rows="1" cols="30"></textarea>
        </div>
    </body>
</html>

这篇关于如何在单击按钮时复制 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆