java关闭窗口的代码_java服务端返回关闭当前支付宝/微信h5窗口

这段代码主要用于处理HTTP请求头中的`user-agent`字段,判断是否来自微信或支付宝客户端。如果用户代理包含`micromessenger`,则注入JavaScript代码用于微信内关闭窗口;如果是`alipay`,则注入代码用于支付宝内关闭网页。这通常应用于移动应用内的H5页面交互。
摘要由CSDN通过智能技术生成

String userAgent = request.getHeader("user-agent").toLowerCase();

PrintWriter writer = response.getWriter();

StringBuilder sb = new StringBuilder();

//微信客户端

if(userAgent.indexOf("micromessenger") != -1){

sb.append("");

sb.append("");

sb.append("");

sb.append("

sb.append("if(typeof window.WeixinJSBridge=='undefined'){$(document).on('WeixinJSBridgeReady',function(){WeixinJSBridge.call('closeWindow')})}");

sb.append("");

sb.append("");

}

//支付宝

else if(userAgent.indexOf("alipay") != -1){

sb.append("");

sb.append("");

sb.append("");

sb.append("

sb.append("if(typeof window.AlipayJSBridge=='undefined'){$(document).on('AlipayJSBridgeReady',function(){AlipayJSBridge.call('closeWebview')})}");

sb.append("");

sb.append("");

}

writer.write(sb.toString());

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值