url.ts 305 B

1234567891011
  1. const ALLOWED_PROTOCOLS = ['https:', 'http:']
  2. export const openURL = (content: string) => {
  3. const url = new URL(content, document.location.href)
  4. if (!ALLOWED_PROTOCOLS.includes(url.protocol)) {
  5. throw new Error(`Not opening URL with protocol ${url.protocol}`)
  6. }
  7. window.open(url, '_blank')
  8. }