回答編集履歴

1

調整

2023/02/27 06:14

投稿

yambejp
yambejp

スコア114915

test CHANGED
@@ -1 +1,45 @@
1
1
  状況がわかりませんが、新たに追加する要素のonloadで検出すればいいのでは?
2
+ - sample.php(わざと遅延させるサンプル)
3
+ ```PHP
4
+ <?PHP
5
+ sleep(3);
6
+ print "content";
7
+ ```
8
+ SPAであれば呼び出すfetchなどにロード状況を仕込む
9
+ ```javascript
10
+ <script>
11
+ window.addEventListener('DOMContentLoaded', ()=>{
12
+ const url="sample.php";
13
+ btn.addEventListener('click',e=>{
14
+ fetch(url).then(res=>res.text()).then(txt=>{
15
+ container.innerHTML=txt;
16
+ console.log('loaded');
17
+ })
18
+ });
19
+ });
20
+ </script>
21
+ <input type="button" value="load" id="btn">
22
+ <div id="container"></div>
23
+ ```
24
+ もしくはcontainerをMutationObserverで監視するとか
25
+ ```javascript
26
+ <script>
27
+ window.addEventListener('DOMContentLoaded', ()=>{
28
+ const url="sample.php";
29
+ const mo = new MutationObserver(n=>{
30
+ console.log('loaded');
31
+ });
32
+ const opt = {
33
+ childList:true,
34
+ };
35
+ mo.observe(container, opt);
36
+ btn.addEventListener('click',e=>{
37
+ fetch(url).then(res=>res.text()).then(txt=>{
38
+ container.innerHTML=txt;
39
+ })
40
+ });
41
+ });
42
+ </script>
43
+ <input type="button" value="load" id="btn">
44
+ <div id="container"></div>
45
+ ```