Answer the question
In order to leave comments, you need to log in
How to execute a script on button click?
Hello, help me load the MC.ini file with the username={login} information recorded when clicking on the link with id=""
Here I have compiled the code, but for some reason it only works after the second click.
Help me find the error or tell me how to download this file.
Thanks in advance!
<script>
function copytext(el) {
var $tmp = $("<input>");
$("body").append($tmp);
$tmp.val($(el).text()).select();
document.execCommand("copy");
swal("IP адрес скопирован!", " ", {
buttons: {
cancel: "Ок",
catch: {
text: "Запустить игру",
value: "catch",
},
},
})
.then((value) => {
switch (value) {
case "catch":
swal("Программа сейчас запустится!", "Подождите немного. Приятного отдыха!", "success");
/* Кликает на ссылку #play788mc */
document.querySelector('.playrustex').click()
/* Скачивает файл MC.ini */
document.getElementById('todownload').onclick = function() {
let text = "username={username}";
let myData = 'data:application/txt;charset=utf-8,' + encodeURIComponent(text);
this.href = myData;
this.download = 'MC.ini';
}
break;
}
});
$tmp.remove();
}
</script>
<a id="todownload" href="#play788mc" type="button" class="playrustex"></a>
Answer the question
In order to leave comments, you need to log in
<a id="todownload" href="#play788mc" type="button" class="playrustex" onClick="copytext(el)"></a>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question