L
L
l7_7l2019-04-03 10:24:12
JavaScript
l7_7l, 2019-04-03 10:24:12

Automatically click a button on a website when it appears?

There is a site on which the button independently appears. It is necessary that the script automatically clicks on it when it appears and works in the background. And what is the best way to launch it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Proskurin, 2019-04-03
@l7_7l

In general, there is such an API as MutationObserver . It allows you to track changes to certain DOM elements, changes to their attributes, content, and so on. You can hang such a "surveillance" on the parent element, where the button will appear, and when the event in MutationObserver is triggered, look for the button and click on it.
UPD: example
PS: if you have access to the code that adds this element, or at least calls some kind of callback, it's better not to use MutationObserver, because it is slow on its own, and in the wrong hands can lead to serious performance problems.

L
lamer350, 2019-04-03
@lamer350

document.getElementById('yourBtnID').click()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question