Button to close the website

i want to add a button on my wix wesite which when clicked will close the website here is my code that i am embedding but it is not working but when i run this code on my vs code it work here is my website url https://talhamustafa753665.wixsite.com/contact-form " when you will open the website after 3,4 seconds it will show you a lightbox on that lightbox there is a button named"close website which should close the website "
<style>
#colorButton {
padding: 10px 20px;
font-size: 16px;
background-color: #007bff; /* Default color */
color: #fff;
border: none;
cursor: pointer;
border-radius: 5px;
}

#colorButton:hover {
background-color: #0056b3; /* Hover color */
}
</style>
<button id="colorButton">Close Website</button>

<script>
document.getElementById("colorButton").addEventListener("click", function() {
var button = document.getElementById("colorButton");
button.style.backgroundColor = "#dc3545"; // Change button background color to red
setTimeout(function() {
window.close(); // Close the window
}, 1000); // Delay closing the window for 1 second (1000 milliseconds)
});
</script>
<style>
#colorButton {
padding: 10px 20px;
font-size: 16px;
background-color: #007bff; /* Default color */
color: #fff;
border: none;
cursor: pointer;
border-radius: 5px;
}

#colorButton:hover {
background-color: #0056b3; /* Hover color */
}
</style>
<button id="colorButton">Close Website</button>

<script>
document.getElementById("colorButton").addEventListener("click", function() {
var button = document.getElementById("colorButton");
button.style.backgroundColor = "#dc3545"; // Change button background color to red
setTimeout(function() {
window.close(); // Close the window
}, 1000); // Delay closing the window for 1 second (1000 milliseconds)
});
</script>
2 Replies
SoulSkrix
SoulSkrix9mo ago
Hi Moni, you can't do that in JavaScript unless you opened the same window with JavaScript. It is a browser security precaution.
Moni
MoniOP9mo ago
thanks
Want results from more Discord servers?
Add your server