windows.open使用
<!DOCTYPE html>
<html lang="zh"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>window.open学习</title>
</head><body><button id="blank">_blank</button><button id="parent">_parent</button><button id="self">_self</button><button id="top">_top</button><button id="name">name</button><button id="new">new</button><button id="fullscreen">fullscreen</button><script>document.querySelector("#blank").addEventListener('click', () => {window.open("https://www.baidu.com", "_blank");})document.querySelector("#parent").addEventListener('click', () => {window.open("https://www.baidu.com", "_parent");})document.querySelector("#self").addEventListener('click', () => {window.open("https://www.baidu.com", "_self");})document.querySelector("#top").addEventListener('click', () => {window.open("https://www.baidu.com", "_top");})document.querySelector("#name").addEventListener('click', () => {window.open("https://www.baidu.com", "");})document.querySelector("#new").addEventListener('click', () => {const myWindow = window.open('', '', 'width=200,height=100');//myWindow.document.location.href = "https://www.baidu.com";myWindow.document.write("<p>这是'我的窗口'</p>");myWindow.focus();})document.querySelector("#fullscreen").addEventListener('click', () => {// 获取屏幕的宽度和高度 var screenWidth = screen.width;var screenHeight = screen.height;const myWindow = window.open("https://www.baidu.com", '', 'width=' + screenWidth + ',height=' + screenHeight);myWindow.focus();})</script>
</body></html>
具体效果复制代码点击查看~~
参考
https://www.runoob.com/jsref/met-win-open.html