JesseUCAVedYou
Member
I've got a short javascript code that copies an ip address based off of the contents of a query selector. In the script is an alert that notifies the user that the IP was copied. I'd like to replace the standard javascript alert with a flashalert instead to better suit the style of the site. What could I do to achieve this?
Code:
<a href="#" data-xf-init="tooltip" onclick="copyIP.call(this)" data-server-ip-copy="0.0.0.0:1234" data-original-title="Copy IP Address" id="js-XFUniqueId1"> <span translate="no"></span> <i class="far fa-copy"></i></a>
JavaScript:
function copyIP() {
// Prevent default action of the anchor tag
event.preventDefault();
// Use 'this' keyword to refer to the clicked element and get its 'data-server-ip-copy' attribute
var ipToCopy = $(this).attr('data-server-ip-copy');
// Use the Clipboard API to copy the value
navigator.clipboard.writeText(ipToCopy).then(function() {
console.log('Copying to clipboard was successful!');
alert("Server ip/port has been successfully copied to your clipboard.");
}, function(err) {
console.error('Could not copy text: ', err);
});
}