When a button is clicked it will scroll to the bottom of the page automatically. I can't see the reason in the code why it is doing it. Is there something I am missing?
Code:
echo "<br>Home Drive : <a class=clear href=$dir>$dir</a><br>";?>
<p id="demo<?php echo $x; ?>"style="position:absolute;left:-1000px;top:-1000px;">
<?php echo $dir ?>
</p>
<button onclick="copy('demo<?php echo $x; ?>')">Copy Home Drive</button> <br><br>
<?php }
echo "</div>";
}
?>
<script>
function copy(element_id) {
var aux = document.createElement("div");
aux.setAttribute("contentEditable", true);
aux.innerHTML = document.getElementById(element_id).innerHTML;
aux.setAttribute("onfocus", "document.execCommand('selectAll',false,null)");
document.body.appendChild(aux);
aux.focus();
document.execCommand("copy");
document.body.removeChild(aux);
}
</script>
Thanks
Here is the updated code. After testing Professor Abronsius method it seems to cause the page to not load. Am I missing anything? <?php
$LDAPFieldsToFind=array
("homedirectory", "displayname", "samaccountname"); //The data we want to find from the search
$numresults=$info["count"];
echo"<div style='position: fixed; float: right; padding-left: 450px;'><a class=clear href=javascript:history.go(-1)>Search again</a></div>";
echo "<div><p>There are <b>$numresults</b> results for your search '<i><b>$SearchFor</i></b>'";
if ($numresults>0){
echo " these are:</p></div>";
echo "<div>";
<?php }
echo "</div>";
}
else echo "</div><div><br><a class=clear href=javascript:history.go(-1)>Search again</a></div>";
ldap_close($cnx);
?>
<script>
document.querySelectorAll('div.usr button').forEach(bttn=>bttn.addEventListener('click',function(e){
navigator.clipboard.writeText( this.parentNode.textContent )
.then(()=>{
alert( 'Copied' )
})
.catch( err=>alert( err ) )
}))
</script>