Discourse가 SPA(싱글 페이지 애플리케이션)이므로, 문서의 “DOMContentLoaded” 이벤트에 의존하는 것은 큰 도움이 되지 않습니다. 문서의 DOM은 항상 "로드"된 상태이지만, 필요한 요소가 실제로는 존재하지 않을 수 있기 때문입니다. 대신 @merefield님이 언급했듯이 Components를 사용하거나, 다음과 같은 방식을 사용하는 것이 좋습니다: How do you force a script to refire on every page load in Discourse? - #5 by simon. 이렇게 하면 페이지가 변경될 때마다 변경하려는 요소가 존재하는지 코드로 확인할 수 있습니다.
Alteras
(Steven Chang)
4
Related topics
| 글 | 댓글 | 조회수 | 활동 | |
|---|---|---|---|---|
| Custom javascript gets only applied after refresh, creating categories for location plugin | 9 | 150 | 8월 13, 2025 | |
| How to add Javascript to Footer Of Posts? | 3 | 968 | 10월 10, 2021 | |
| A better way to implement custom jQuery code? | 3 | 573 | 2월 18, 2021 | |
| Executing js after DOM loaded | 6 | 3816 | 11월 30, 2018 | |
| How do you force a script to refire on every page load in Discourse? | 38 | 21531 | 3월 12, 2020 |