所以我在一个网站上,我想获得一个链接。我要获取的链接显示在网站上,但在html文件中不可见。有一个复制按钮,可将链接复制到剪贴板。我想获得链接,有人知道我如何获得它吗?
html看起来像这样:
<div class="containerInvite">
<div class="title">Invite your friends!</div>
<div class="inviteBar">
<input type="text" readonly id="invite"> --Here should be the link
<button class="button btn btn-primary"
id="inviteCopyButton">Copy</button> --The Button that copies the link
</div>
</div>
最佳答案
要仅从javascript中读取id="invite"
输入的值,请使用:
document.getElementById("invite").value;
如果您希望按钮将值复制到剪贴板中,请创建一个函数
function copyLink() {
//Get the text field
var copyText = document.getElementById("invite");
//Select the text field
copyText.select();
//Copy the text inside the text field
document.execCommand("copy");
}
然后加
onclick="copyLink()"
在您的按钮中。或附加“点击”事件
关于javascript - 抓取: Get Link that is only visible on the website not in the html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52513120/