/**
* 获取token id url固定传(window.location.href , ?后面的前缀)
*/
getVideoId(url: string, id: string) {
let startIndex = url.lastIndexOf(id);
let idAfterData = url.substring(startIndex, url.length);
let endIndex;
if (startIndex === -1){ // 判断有无id这个字段 如果没有返回空字符串
return ''
}
// 判断是否是最后一个参数
if (idAfterData.indexOf("&") === -1) {
if (idAfterData.indexOf("#") === -1){
endIndex = url.length;
}else {
endIndex = idAfterData.indexOf("#") + startIndex
}
} else {
endIndex = idAfterData.indexOf("&") + startIndex;
}
return url.substring(startIndex + id.length, endIndex);
}
// 用法
this.getVideoId(window.location.href, "userId="),