Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Detect if HTML5 video is local

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thank you.

>Solution :

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading