js模拟a标签点击在新窗口打开

来源:互联网 发布:linux ant命令 编辑:程序博客网 时间:2024/05/22 15:44
这个会被浏览器拦截
var el = document.createElement("a");document.body.appendChild(el);el.href = "http://www.baidu.com"; //url 是你得到的连接el.target = '_new'; //指定在新窗口打开el.click();document.body.removeChild(el);
这个不会被拦截
<a href="" id="alink" target="_blank" style="display: none"><span id="spanlink">test</span></a> <input type="button" value="点我弹出新页面" onclick="targetClick()" /> 
function targetClick() { $("#alink").attr("href", "http://www.163.com"); $("#spanlink").click(); return false; }

原创粉丝点击