What js code allows when you reload the page or even when you first visit it - automatically select some element (by clicking on which a certain load code is executed). Tobish came in and immediately plunged, no need to press the button.
- class active is not that - Kryshtop
- 2write the function to js, and call when the page loads. - nueq
|
3 answers
The process of loading an HTML document: DOMContentLoaded - the browser has completely loaded HTML, and built a DOM tree. load - the browser has loaded all the resources. beforeunload / unload - leaving the page.
//Событие onload на window срабатывает, когда загружается вся страница. window.onload = function() { console.log("Все загрузилось"); }; <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <script> //DOMContentLoaded – браузер полностью загрузил HTML, и построил DOM-дерево. function ready() { console.log('DOM готов'); console.log("Тут можно выполнять необходимые действия"); } document.addEventListener("DOMContentLoaded", ready); </script> </body> </html> |
location.href = "download.php" or better on php header
|
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <button type="button" id="ya">Нажать</button> <script> function raz() { alert("Здравствуйте"); } raz(); // функция запускается без события document.getElementById("ya").addEventListener("click", raz); </script> </body> </html> |