在浏览器新的标签页中打开页面, 通过 js下载文件

open-new-page

As you know, if you want to open a new tab in browser or in the iframe by window.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

版权声明:

1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。
2、网站不提供资料下载,如需下载请到原作者页面进行下载。