回答編集履歴

2

chousei

2023/04/13 07:29

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -3,27 +3,29 @@
3
3
  一応私の案に少し興味がありそうですので、具体的にはこんなかんじ
4
4
  ```javascript
5
5
  <script>
6
- window.addEventListener('popstate', (e)=>{
6
+ window.addEventListener('popstate', ()=>{
7
7
  history.pushState(null, null, null);
8
8
  });
9
9
  window.addEventListener('DOMContentLoaded', ()=>{
10
+ const dlg=document.querySelector('dialog');
10
11
  history.pushState(null, null, null);
11
12
  btn.addEventListener('click',()=>{
12
13
  history.go(-2);
13
14
  });
14
- document.querySelector('dialog').addEventListener('close', e => {
15
+ dlg.addEventListener('close', () => {
15
- if(e.target.returnValue!="ok" ){
16
+ if(dlg.returnValue!="ok" ){
16
- document.querySelector('dialog').showModal();
17
+ dlg.showModal();
17
18
  }
18
19
  });
19
- document.querySelector('dialog').showModal();
20
+ dlg.showModal();
20
21
  });
21
22
  </script>
22
23
  <dialog>
23
24
  <form method="dialog">
24
- OKボタンをしてください
25
+ OKボタンをしてください
25
26
  <button type="submit" value="ok">OK</button>
26
27
  </form>
27
28
  </dialog>
28
29
  <input type="button" id="btn" value="btn">
30
+
29
31
  ```

1

chousei

2023/04/13 07:24

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -7,7 +7,7 @@
7
7
  history.pushState(null, null, null);
8
8
  });
9
9
  window.addEventListener('DOMContentLoaded', ()=>{
10
- history.pushState(null, null, '');
10
+ history.pushState(null, null, null);
11
11
  btn.addEventListener('click',()=>{
12
12
  history.go(-2);
13
13
  });