欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

在jquery中如何打开新的窗口

程序员文章站 2022-03-24 13:52:10
...

在jquery中打开新窗口的方法:1、创建一个form表单,通过表单提交来实现新标签页打开;2、通过“window.open('_blank');”来打开;3、通过“setTimeout(window.open(...);”方式来打开。

在jquery中如何打开新的窗口

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

推荐:《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' ;

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

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

以上就是在jquery中如何打开新的窗口的详细内容,更多请关注其它相关文章!

相关标签: jquery