惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
GbyAI
GbyAI
WordPress大学
WordPress大学
月光博客
月光博客
V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Google DeepMind News
Google DeepMind News
H
Help Net Security
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
博客园 - 司徒正美
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
Blog — PlanetScale
Blog — PlanetScale
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Microsoft Azure Blog
Microsoft Azure Blog
V
V2EX
L
LangChain Blog
腾讯CDC
T
The Blog of Author Tim Ferriss
量子位

博客园 - 牦牛

Linux常用命令 错误:80040154 没有注册类 的问题 [转]Java实现定时任务的三种方法 访问IIS网站需要输入用户名密码(非匿名登录)问题汇总 IE10、IE11 User-Agent 导致的 ASP.Net 网站无法写入Cookie 问题 端口占用问题 中国电信翼支付网关接口接入 修改Tomcat响应请求时返回的Server内容 Eclipse常用设置 Tomcat服务无法启动的问题 JavaScript继承的模拟实现 Windows Server 2008 小操作汇总 手机也能连VPN,再来个远程控制PC这种事你以为我会随便说么! - 牦牛 Windows下Git服务器搭建及使用过程中的一些问题 Oracle PL/SQL中的循环处理(sql for循环) CSS的display小记 博客园添加访问人数统计 IIS故障问题(Connections_Refused)分析及处理 Windows Server 2008自定义桌面
模拟用户点击弹出新页面
牦牛 · 2014-04-08 · via 博客园 - 牦牛

模拟用户点击弹出新页面

  相信用过window.open的小伙伴们都遇到过被浏览器拦截导致页面无法弹出的情况;我们换下思路,什么情况下的新页面弹出才不会被浏览器拦截呢?比如<a />标签这种就不会;那么我们只要模拟下用户去主动点击这个<a />标签就不会有拦截的问题了。

先定义好HTML标签:

<a href="" id="alink" target="_blank" style="display: none"><span id="spanlink">test</span></a>
<input type="button" value="点我弹出新页面" onclick="targetClick()" />


然后在JS中给<a />标签赋值并触发点击事件:

1       function targetClick() {
2             $("#alink").attr("href", "http://www.163.com");
3             $("#spanlink").click();
4             return false;
5         }

OK,这下页面的弹出就畅通无阻了。

posted on 2014-04-08 12:27  牦牛  阅读(1969)  评论(3)    收藏  举报