当前位置:网站首页>关闭页面时向后台发送消息
关闭页面时向后台发送消息
2022-07-28 08:03:00 【仲夏你的梦】
语法:
navigator.sendBeacon(url, data);返回值:
当用户代理成功把数据加入传输队列时,sendBeacon() 方法将会返回 true,否则返回 false。
代码:
window.addEventListener("beforeunload", (e) => {
const data = {name: "我是豆豆"};
window.navigator.sendBeacon("http://127.0.0.1:1991/loginout", JSON.stringify(data));
});不管是刷新页面还是关闭页面,后台都能接收到前端发送过来的请求,完美实现需求。
边栏推荐
- Path and attribute labels of picture labels
- Service current limiting and fusing of micro service architecture Sentinel
- When I use MySQL CDC, there are 100 million pieces of data in the source table. In the full volume phase, when I synchronize 10 million, I stop, and then pass
- C #, introductory tutorial -- debugging skills and logical error probe technology and source code when the program is running
- Warehouse of multiple backbone versions of yolov5
- Use of tkmapper - super detailed
- [activity registration] User Group Xi'an - empowering enterprise growth with modern data architecture
- 【单细胞高级绘图】07.KEGG富集结果展示
- Distributed system architecture theory and components
- Sentry log management system installation and use tutorial
猜你喜欢

快速搭建一个网关服务,动态路由、鉴权的流程,看完秒会(含流程图)

Explain cache consistency and memory barrier

1w5字详细介绍分布式系统的那些技术方案

从开发转测试:我从零开始,一干就是6年的自动化测试历程

Different HR labels

Hcip day 8

Dapp安全总结与典型安全事件分析

1w5 words to introduce those technical solutions of distributed system in detail

NPM and yarn use (official website, installation, command line, uploading your own package, detailed explanation of package version number, updating and uninstalling package, viewing all versions, equ
![第2章-2 计算分段函数[1]](/img/40/cad6bf92849624199af0fd1ba1d433.jpg)
第2章-2 计算分段函数[1]
随机推荐
1w5字详细介绍分布式系统的那些技术方案
Go synergy
kubernetes之Deployment
Kubernetes cluster configuration dashboard service
Flink window & time principle
49 opencv deep analysis profile
Go interface advanced
Basic syntax of jquey
JS inheritance method
C #, introductory tutorial -- debugging skills and logical error probe technology and source code when the program is running
Network interface network crystal head RJ45, Poe interface definition line sequence
golang 协程的实现原理
PostgreSQL: cannot change the type of column used by a view or rule
TXT文本文件存储
Vs2015 use dumpbin to view the exported function symbols of the library
图片批处理|必备小技能
Argocd Web UI loading is slow? A trick to teach you to solve
Hcip day 9_ BGP experiment
Service current limiting and fusing of micro service architecture Sentinel
You're not still using xshell, are you? This open source terminal tool is yyds!