zhin dins
zhin dins

Reputation: 95

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

Thank you.

Upvotes: 1

Views: 65

Answers (1)

Unmitigated
Unmitigated

Reputation: 89159

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);

Upvotes: 1

Related Questions