如何使用JavaScript一次复制多个网址?

时间:2019-03-21 04:27:23

标签: javascript jsp

我创建了一个如下所示的JSP页面:

Screenshot

每个文件都有其自己的唯一URL链接,我可以单独复制它们而不会出现任何问题。但是,我添加了复选框,以便用户可以勾选所需的文件,然后单击Copy Selected URL

例如,如果用户选中了两个链接并将其粘贴在记事本上,则它应类似于:

LINK1

LINK2

这是我的JSP页面,显示您可以看到的屏幕截图:

<table class="filesTbl">
    <tr>
        <th width="1%">
            Checkbox
        </th>
        <th width="1%">
             No
        </th>
        <th width="20%">
            File Name
        </th>
        <th width="50%">
            Unique URL
        </th>
        <th width="1%">
            Edit
        </th>
        <th width="1%">
            Copy
        </th>
        <th width="1%">
            Email
        </th>

    </tr>

<%
    //need to input logic to populate data on each row

    int counter=0;

    String[] split = request.getParameter("nodeID").split(",",0);
    for(int i=0;i<split.length;i++){

        long file=Long.parseLong(split[i]);

        List files = fileFacade.list_items(file);
        for (Iterator rstltr = files.iterator(); rstltr.hasNext();) {
            Fmedia fv = (Fmedia) rstltr.next();
            Node nd = nodeFacade.get(fv.getNodeid(), false);
            // Fmedia fm = fileFacade.get_file(fv.getNodeid());

            int count = 0;
            count++;
            long fileid= nd.getNodeid();



%>


    <tbody>
    <tr>
        <td width="5%">
            <!--Display Checkbox   -->
            <input type="checkbox" name="name1" />&nbsp;
        </td>

        <td>
            <!--Display No   -->
            <% counter=counter+1;
                out.print(counter);

            %>


        </td>
        <td width="28%">

            <!-- Display Filename   -->
            <%=nd.getNodedesc()%>



        </td>
        <td width="100%">
            <!-- Display URL -->
               <%  SettingsFacadeLocal settingFacade = (SettingsFacadeLocal)ctx.lookup("java:comp/env/settings");
                   String redirectURL = settingFacade.get("SERVER_URL").getAtval();
                   //declare a timestamp for unique URL
                  // String timeStamp=new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new java.util.Date());
                  // String hash = org.apache.commons.codec.digest.DigestUtils.sha256Hex(timeStamp);

                   SecureRandom secureRandom=new SecureRandom();
                   byte[] token = new byte[12];
                   secureRandom.nextBytes(token);
                   String hash= new BigInteger(1, token).toString(12);

               %>

            <%=redirectURL+"/repository/file/view/viewPDF.jsp?f0="+nd.getNodeid()+"&ts="+hash%>
            <%

                fileFacade.insert_url(nd.getNodeid(),"f0="+nd.getNodeid()+"&ts="+hash);

                //fileFacade.insert_url(nd.getNodeid(),"{syscont url}/repository/file/view/viewPDF.jsp?{url});

            %>


        </td>
        <td>
            <!-- Display EDIT/DEL -->

        </td>
        <td> <!-- Display COPY feature -->

            <input type="button" value="Copy URL" onclick="copyURL('<%=redirectURL+"/repository/file/view/viewPDF.jsp?f0="+nd.getNodeid()+"&ts="+hash%>')">

        </td>


    </tr>

    </tbody>


<%}}
%>


    <script>
        function copyURL(url) {
            var copyText = url;
            var el = document.createElement('textarea');
            el.value = copyText;
            el.setAttribute('readonly', '');
            el.style = {
                position: 'absolute',
                left: '-9999px'
            };
            document.body.appendChild(el);
            el.select();
            document.execCommand('copy');
            document.body.removeChild(el);
            alert("You have copied the URL");
        }
    </script>





</table>




</div>

<!--Copy button to copy multiple links -->

<div class="wrapper">
<input type="button" value="Copy Selected URL">
</div>
<style>


    .wrapper {
        position: absolute;
        top: 90%;
        left: 5%;
    }

</style>

</body>

我相信我添加的复选框必须唯一,才能分别标识每个URL。

我对JavaScript不太熟悉,可以通过编程方式完成吗?

0 个答案:

没有答案