fix: base()从script src反推模块前缀——嵌入主页面时pathname推导失效导致URL缺/scense_game
This commit is contained in:
parent
979cc39687
commit
269e6467ab
@ -9,6 +9,13 @@ window.scenseGameList = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function base() {
|
function base() {
|
||||||
|
// 嵌入主页面时 location.pathname 是主页面路径,推导失败;
|
||||||
|
// 改为从本 js 的 <script src> 反推模块前缀(/scense_game/game_list.js -> /scense_game)
|
||||||
|
var scripts = document.querySelectorAll('script[src]');
|
||||||
|
for (var i = 0; i < scripts.length; i++) {
|
||||||
|
var m = (scripts[i].src || '').match(/^(.*\/)game_list\.js/);
|
||||||
|
if (m) return m[1].replace(/\/+$/, '');
|
||||||
|
}
|
||||||
var p = window.location.pathname.replace(/\/game\/.*$/, '');
|
var p = window.location.pathname.replace(/\/game\/.*$/, '');
|
||||||
return p.replace(/\/+$/, '');
|
return p.replace(/\/+$/, '');
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user