2.0.0 • Published 6 years ago

open-new-page v2.0.0

Weekly downloads
4
License
ISC
Repository
github
Last release
6 years ago

open-new-page

NPM downloads JS gzip size Npm package Language License

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

2.0.0

6 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago