open-new-page
v2.0.0
Published
在浏览器新的标签页中打开页面
Downloads
112
Readme
open-new-page
As you know, if you want to open a new tab in browser or in the
iframe
bywindow.open()
, browser will prevent jump action, and you can use this to solve the problem. Besides, it's also useful when you want to download files with js.
Install
npm install open-new-page --save
Start
simple open page in new tab
import OpenNewPage from 'open-new-page'
OpenNewPage('https://www.baidu.com')
set method and params
openNewPage({
url: 'http://www.baidu.com',
method: 'GET',
params: {
a: 1,
b: true,
c: [1, 2, 3],
d: { d1: 1 },
e: '123',
f: null,
g: undefined
}
})
download files
openNewPage('https://dn-quietcoder.qbox.me/table.xlsx')
download image
openNewPage({
url: 'https://dn-quietcoder.qbox.me/avatar-1.jpg',
params: {
a: 1,
b: true,
c: [1, 2, 3],
d: { d1: 1 },
e: '123',
f: null,
g: undefined
},
useATag: true
// fileName: 'xxx.jpg'
})
just use in html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://unpkg.com/open-new-page/index.global.js"></script>
</head>
<body>
<button id="btn">open new page with params</button>
<script>
var btn = document.getElementById('btn')
btn.addEventListener('click', function () {
openNewPage({
url: 'http://www.baidu.com',
method: 'GET',
params: {
a: 1,
b: true,
c: [1, 2, 3],
d: { d1: 1 },
e: '123',
f: null,
g: undefined
}
})
})
</script>
</body>
</html>
LICENSE
MIT