Skip to content

Instantly share code, notes, and snippets.

@thc282
Last active April 22, 2024 16:15
Show Gist options
  • Save thc282/db329adbca2509361050db2b5b448536 to your computer and use it in GitHub Desktop.
Save thc282/db329adbca2509361050db2b5b448536 to your computer and use it in GitHub Desktop.
window.open with android / IOS
//Get the device type
let system = navigator.userAgent
let isAndroid = system.indexOf('Android') > -1 || system.indexOf('Adr') > -1 // android终端
let isiOS = !!system.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) //ios终端
let Androidurl = "https://www.androidurl.com"
let Appleurl = "https://www.Appleurl.com"
// Open the Google Maps link in a new tab
var newWindow = window.open('', '_blank') // Noted: this window.open() must be call outside the async, since safari blocked .open() inside any async function
newWindow.location.href = isAndroid ? Androidurl : (isIPhone ? Appleurl : Defaulturl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment