Trying to make a Alert button in tampermonkey

395 Views Asked by At

I have been trying to get a alert button working in tampermonkey but i dont seem to get it working. Here is my script;

var button = document.createElement("Button");
button.innerHTML = "Title";
button.style = "top:15px;left:15px;position:absolute;z-index:99999; width:50px; height 50px; background_color; ff0000";
button.onclick = "alert('Test Alert')"
document.body.appendChild(button);
1

There are 1 best solutions below

0
CertainPerformance On BEST ANSWER

You can only assign a function to onclick. If you assign a string, no function will be executed when a click occurs:

var button = document.createElement("Button");
button.innerHTML = "Title";
button.style = "top:15px;left:15px;position:absolute;z-index:99999; width:50px; height 50px; background_color; ff0000";
button.onclick = () => alert('Test Alert');
document.body.appendChild(button);