Home > Software design >  Detect if HTML5 video is local
Detect if HTML5 video is local

Time:12-19

I would like to ask how to detect if the video source is local or external

Is the best way to use regex to detect video source and define it local or external, like this? => https?:\/\/

Or are there an API for this? What is the best practice? Thank you

Thank you.

CodePudding user response:

You can set the URL as the href of an anchor and check its host.

const a = document.createElement('a');
a.href = '/local';
console.log(a.host === location.host); // internal
a.href = 'https://example.com';
console.log(a.host, location.host);

  • Related