检测HTML5视频是否是本地的



我想问一下如何检测视频源是本地的还是外部的

是最好的方法来使用正则表达式检测视频源和定义它本地或外部,像这样?=比;https?://

或者有这样的API吗?什么是最佳实践?谢谢你

谢谢。

您可以将URL设置为锚的href并检查其主机

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

相关内容