js jquery新窗口打开的几种方式
第一种:创建一个form表单,通过表单提交来实现新标签页打开。
var form = document.createElement(‘form‘);
form.action = ‘www.baidu.com?id=1‘;
form.target = ‘_blank‘;
form.method = ‘POST‘;
document.body.appendChild(form);
form.submit();
第二种:
var tempwindow=window.open('_blank');
tempwindow.location='www.baidu.com' ;
第三种:(与第一种相似)
/* 在新窗口中打开 */
function openNewWindow(url) {
var a = document.createElement('a');
a.setAttribute('href', url);
a.setAttribute('target', '_blank');
var id = Math.random(10000, 99999);
a.setAttribute('id', id);
// 防止反复添加
if (!document.getElementById(id)) {
document.body.appendChild(a);
}
a.click();
}
//方法调用
openNewWindow('www.baidu.com');