回答編集履歴
1
ホスト部のハードコードを除去
answer
CHANGED
@@ -2,4 +2,17 @@
|
|
2
2
|
```js
|
3
3
|
window.location.href = `https://sample.com/${Math.random() < 0.5? 'B' : 'C'}${window.location.search}`;
|
4
4
|
```
|
5
|
-
ではダメでしょうか
|
5
|
+
ではダメでしょうか
|
6
|
+
|
7
|
+
追記 Oct 9, 2019 9:30pm
|
8
|
+
ホストは変わらないのですね。
|
9
|
+
```js
|
10
|
+
window.location.href = `${window.location.origin}/${Math.random() < 0.5? 'B' : 'C'}${window.location.search}`;
|
11
|
+
|
12
|
+
// 上のだと1行が長くなって見づらいので、分割して書くならこれでもいいかと
|
13
|
+
window.location.href = [
|
14
|
+
window.location.origin,
|
15
|
+
Math.random() < 0.5? '/B' : '/C',
|
16
|
+
window.location.search
|
17
|
+
].join('');
|
18
|
+
```
|