Answer the question
In order to leave comments, you need to log in
How can I make the script work only on one page?
Tell me how to make the script work only on one specific page?
It is necessary so that on all pages there is no error about not finding a class or ID.
Script:
const headerWindow = document.getElementById('header_window'),
openHeaderWindow = document.getElementById('control_avatar'),
closeHeaderWindow = document.getElementsByClassName('close_window')[0];
openHeaderWindow.onclick = function () {
headerWindow.style.display = 'block';
}
closeHeaderWindow.onclick = function () {
headerWindow.style.display = 'none';
}
window.onclick = function(e) {
if (e.target == headerWindow) {
headerWindow.style.display = 'none';
}
}
Answer the question
In order to leave comments, you need to log in
Check if there is such a selector on the page and then execute the code
Make sure that this script is present only on the desired page, and not on the rest.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question