iT邦幫忙

1

VUE 捕獲關閉瀏覽器 或者 F5(刷新網頁) 事件

前文:我因為看到 H大作品 ,https://ithelp.ithome.com.tw/articles/10217518
自動備份IT幫發文

我仿照大神導入自己項目時候,發現可以備份沒錯,但是無法指定是否要備份,我想說當使用者 關閉瀏覽器 或者 F5(刷新網頁)時,可以跳出 一個 Modal 框 ,選擇是否要備份,或者離開

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
dragonH
iT邦超人 5 級 ‧ 2019-10-31 17:19:54
最佳解答

f5 refresh 可以用

window.onbeforeunload

code

window.onbeforeunload = () => {
    return confirm('確定要離開?')
}

return 什麼不重要

因為也沒辦法 custom

甲土豆 iT邦新手 5 級 ‧ 2019-10-31 20:02:32 檢舉

感謝H大神,救世主阿 /images/emoticon/emoticon02.gif

dragonH iT邦超人 5 級 ‧ 2019-10-31 20:16:52 檢舉

/images/emoticon/emoticon42.gif/images/emoticon/emoticon42.gif/images/emoticon/emoticon42.gif

不過 codepen 有辦法做到 關閉 tab 或 瀏覽器時

也跳出提示

還沒時間去研究它怎麼做的

我要發表回答

立即登入回答