小兔网

jquery中打开新窗口的方法:首先创建一个form表单;然后通过表单提交来实现打开新窗口,如【form.target = ‘_blank‘;form.method = ‘POST‘;】。

jquery中怎么打开新窗口

本教程操作环境:windows10系统、jquery2.2.4版,该方法适用于所有品牌电脑。

(学习视频分享:jquery视频教程

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' ;

第三种:

setTimeout(window.open('www.baidu.com'), 500);

第四种:(与第一种相似)

/* 在新窗口中打开 */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');

注:以上方法js中均可适用,若页面跳转的动作是在ajax方法执行后的,需要设置ajax同步执行。添加属性:async:false。如:

$.ajax({                type: 'post',                data: param,                url: 'ActionUrl',                dataType: 'json',                async:false,                success: function (msg) {openNewWindow('www.baidu.com');}

相关推荐:js教程

以上就是jquery中怎么打开新窗口的知识。速戳>>知识兔学习精品课!