npm.io
1.0.0 • Published 6 years ago

nav_share_polyfill

Licence
ISC
Version
1.0.0
Deps
0
Size
18 kB
Vulns
0
Weekly
0

A polyfill for navigator.share()

Demo: test here


A good navigator.share polyfill. Looks like native. It's size is about 4kb. Eazy to use, free and open-source.
Usage:
var data  =  {
    title:  'navigator.share() polyfill',
    text:  'A polyfill for navigator.share()',
    url:  location.href,
}
navigator.share(data)
.then(function()  {
	alert('You shared it!')
})
.catch(function(e)  {
	alert('Error');
});

Don't forgget to include the script:

https://isaqueks.github.io/nav_share_polyfill/navigator.share.js

OR (minified)

https://isaqueks.github.io/nav_share_polyfill/navigator.share.min.js

If you want to force the polyfill (even if the browser supports navigator.share()), insert this code (before the main script):

window.FORCE_SHARE_POLYFILL = true;

Works for mobile and desktop (most desktop browsers doesn't support native navigator.share())

Keywords