2017-11-25 54 views
-1

这里是我的HTML代码:试图让一个搜索按钮,可以重定向到另一个网址,并复制剪贴板上的重定向URL

<input id="text" type="text" name="text"> 
    <input type="button" name="page1" onclick="javascript:window.open('http://example.com/' + this.name + '/' + document.getElementById('text').value)"> 

如果你把在该领域的任何文本并单击该按钮它会重定向到http://example.com/page1/anytext 我试图让这个按钮能够重定向到URL并将其复制到剪贴板。因此,如果有任何访问者在该字段上输入anytext,它将复制网址http://example.com/page1/anytext并重定向到该网址。

+2

的可能的复制[?如何复制JavaScript中的剪贴板(https://stackoverflow.com/questions/400212/how-do-i-copy-to -the-clipboard-in-javascript) – Ali

回答

0

如下:

function myCopyFunction() { 
    var copyText = document.getElementById("page1"); 
    copyText.select(); 
    document.execCommand("Copy"); 
    alert("Copied the text: " + copyText.value); 
} 
+0

我必须这样写这段代码吗? ()“; alert(”copy“); alert(”copy“); (“复制文本:”+ copyText.value);}>' – user8481790

+0

将函数声明放到HTML之外 –