【html】window.open()被部分浏览器拦截问题
2024-08-26 12:13:34
一、原因:
1、因为在chrome的安全机制里面,非用户触发的window.open方法,是会被拦截的;
二、什么情况下不会被拦截或会被拦截?
1.
$('#btn').click(function () {
//不会被拦截
window.open(url)
});
2.
$('#btn').click(function () {
$.ajax({
url: 'xxxx.com',
success: function (url) {
//会被拦截
window.open(url);
}
})
});
分析原因:
用户没有直接发出window.open请求,而是发出一个ajax请求,window.open方法被放在了ajax的回调函数里,这样的情况就会被拦截了;
三、既然发现那就解决:
$('#btn').click(function () {
//打开一个不被拦截的新窗口
var newWindow = window.open();
$.ajax({
url: 'xxxx.com',
success: function (url) {
//修改新窗口的url
newWindow.location.href = url;
}
})
});//先在回调函数之前打开新窗口,后再加载url
最新文章
- c语言的学习秘籍之链表
- 声明replicated属性之后我编译不通过的问题
- maven 错误No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format
- Ping批量函数
- Linux命令行批量替换多文件中的字符串【转】
- delphi 完全控制Excel 文件
- C# 隐藏和覆盖
- (转)asp.net分页存储过程
- Tsung测试统计报告说明
- C#读书笔记之object类的基本方法
- python学习day16 模块(汇总)
- linux 使用不安全的sprintf函数,存储字符越界导致程序莫名崩溃问题
- oracle插入数据问题
- win系统 Mysql 5.7.19 zip 安装
- 树莓派进阶之路 (003) - Raspberry Pi(树莓派)国内软件源
- HBase写入性能及改造——multi-thread flush and compaction(续:详细测试数据)[转]
- Echarts 曲线数少于图例数解决方法
- Developing modules for the Apache HTTP Server 2.4
- codevs 3235 战争
- IO流-递归遍历目录下指定后缀名结尾的文件名称