Home > Web Front-end > JS Tutorial > body text

How to open a new window in jquery

藏色散人
Release: 2020-11-30 16:29:18
Original
4806 people have browsed it

How to open a new window in jquery: 1. Create a form and submit the form to open a new tab; 2. Open it through "window.open('_blank');"; 3. , open through "setTimeout(window.open(...);" method.

How to open a new window in jquery

The operating environment of this tutorial: windows7 system, jquery version 3.3.1, This method is suitable for all brands of computers.

Recommended: "jquery video tutorial"

Several ways to open a new jquery window

The first one : Create a form and open a new tab through form submission.

var form = document.createElement(‘form‘);
form.action = ‘www.baidu.com?id=1‘;
form.target = ‘_blank‘;
form.method = ‘POST‘;
document.body.appendChild(form);
form.submit();
Copy after login

Second type:

var tempwindow=window.open('_blank');
tempwindow.location='www.baidu.com' ;
Copy after login

Third type: (Similar to the first type)

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

The above is the detailed content of How to open a new window in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template