chrome浏览器onunload方法无法执行window.location.href
记录用户不正常退出,如关闭浏览器的时候,执行onunload方法,跳回后台记录用户已经退出的信息,在ie上可以正常跳转,但在Firefox和chrome上却无法跳转。
测试后发现以下方法可以实现,支持firefox、chrome、ie、360急速模式:
<script type="text/javascript">
window.onbeforeunload = function(){
var res = false;
$(function () {
$.ajax({
url: '@url',
type: 'post',
success: function (data) {
res = true;
}
});
return res;
});
};
window.onunload = function(){
return window.location.href = '@url';
};
</script>
<script type="text/javascript">
window.onbeforeunload = function(){
var res = false;
$(function () {
$.ajax({
url: '@url',
type: 'post',
success: function (data) {
res = true;
}
});
return res;
});
};
window.onunload = function(){
return window.location.href = '@url';
};
</script>
问题:
1.不支持360兼容模式
2.无法区分刷新和关闭,刷新的时候也会直接退出
不知道有没有更好的方法,欢迎留言讨论
done!
chrome浏览器onunload方法无法执行window.location.href的更多相关文章
- window.location.href("url") 无法在chrome和Firefoxz中使用
今天在js代码中加了一句window.location.href(‘url’)希望实现页面的跳转,IE中可以正常使用,但是Firefox却提示window.location is not a func ...
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的使用方法
关于js中"window.location.href"."location.href"."parent.location.href".&qu ...
- window.location.href在微信端不起作用的解决方法?
在我从第一张图的某个活动进去到详情页,点击返回是可以的,这里我是用了一个click事件,window.location.href="某死链接" 但是第二次进去点击之后点击事件是可以 ...
- window.location.href 兼容性问题 (ie 浏览器下设置失效)
window.location.href 兼容性问题 (ie 下设置失效) window.location.href = "../index.html" (ie 浏览器失效) wi ...
- 安卓微信浏览器中window.location.href失效的问题
最近接手一微信项目,测试功能时,发现跳转在android手机上不动了.iso系统可以正常跳转的.解决方法: window.location.href = url + '?v=' + (new Date ...
- a链接onclick="window.location.href=在ie6上面无法执行解决
<a href="javascript:void(0)" onclick="window.location.href=document.getElementById ...
- window.location.href的使用方法
http://hljqfl.blog.163.com/blog/static/40931580201122210573364/ 在写ASP.Net程序的时候,我们常常遇到跳转页面的问题,我们常常使用R ...
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法与区别(跳出iframe方法)
"window.location.href"."location.href"是本页面跳转 "parent.location.href"是上一 ...
- 微信内置的浏览器window.location.href 跳转不兼容问题
1.不兼容苹果手机---->>>>使用模拟触发a标签 <a id="alink" href="http://www.baidu.com&qu ...
随机推荐
- 《JavaScript Dom 编程艺术》读书笔记-第11章
本章简单介绍了HTML5,并推荐了一个好工具Modernizr,用于检测浏览器可能支持的各种特性. HTML5的新特性包括: 可以用来在文档中绘制矢量及位图的<canvas>元素: 可以在 ...
- unigui的页面布局使用
(unigui的页面布局还是很强大的,基本什么的排版都能搞好.前面部分为原文章翻译,翻译不一定很准确,就能看吧,后面有使用说明,有什么不明白的欢迎加我QQ(910300653)一起交流学习) 一.布局 ...
- SharePoint Framework解决方案管理参考(二)
博客地址:http://blog.csdn.net/FoxDave 使用外部脚本 在使用现有的JavaScript脚本库时,开发者可以选择将它们包含在web部件代码包中,或者从外部的URL加载.从外部 ...
- redis总结(一)的持久化的取舍和选择以及作用
1.redis持久化 在客户端发布save的过程中有可能造成阻塞,如一千万条数据同时保存并生成二进制RDB文件的时候,此时就会延迟堵塞. 文件策略是如果存在老的RDB文件,会用新的文件替代老的文件如下 ...
- Linux 安装python3.4
不要动现有的python2环境! 不要动现有的python2环境! 不要动现有的python2环境! 默认yum好用 默认环境不全 1. 安装环境 yum -y install zlib zlib-d ...
- OpenGL的一些名词
搬运自:https://learnopengl-cn.github.io/01%20Getting%20started/10%20Review/ 词汇表 OpenGL: 一个定义了函数布局和输出的图形 ...
- Groovy学习笔记-Java 5新特性支持
1.枚举enum enum CoffeeSize{ SHORT, SMALL, MEDIUM, LARGE, MUG } def orderCoffee(size){ print "Coff ...
- JS高德地图应用 ---- 鼠标点击加入标记 & POI搜索
代码如下 (填入Key值) : <!DOCTYPE html> <html> <head> <meta charset="utf-8"&g ...
- Spring动态获取已注入的对象的方法
1.根据类获取对象 @Autowired ApplicationContext context; GenericMapper<T,String> dao=(GenericMapper< ...
- c#获取url请求的返回值
/// <summary> /// 获取url的返回值 /// </summary> /// <param name="url">eg:http ...