Answer the question
In order to leave comments, you need to log in
Why does the script not see the function in setInterval?
Hello!
Tell me why if you just type this code into the console, it works, and the button is created as part of the extension, but when pressed, it displays:
1 Uncaught ReferenceError: functionName is not defined
function functionName() {
alert('Имя')
}
setInterval(() => {
document.querySelector('.button').innerHTML = '<button onclick="functionName()" type="button" >Показывать имя</button>'
}, 1000)
Answer the question
In order to leave comments, you need to log in
The function functionName
exists in the context of the script content.
When adding a button with a click on it, it will be called in the context of a web page where this function does not exist.
1. Add a button.
2. Add an event listener through it.
Will work. onclick="functionName()"
functionName
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question