回答編集履歴
3
訂正2
answer
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
let { href, pathname, search, hash } = a;
|
17
17
|
console.log(`href: ${href}`);
|
18
18
|
console.log(`path:"${pathname}", search:"${search}", hash:"${hash}"`);
|
19
|
-
if( pathname.match(/.(jpg|png|gif|svg)$/) ) {
|
19
|
+
if( pathname.match(/.(jpg|png|gif|svg)$/i) ) {
|
20
20
|
console.log("img タグが良いっぽい")
|
21
21
|
}
|
22
22
|
else {
|
2
typo の修正
answer
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
let { href, pathname, search, hash } = a;
|
17
17
|
console.log(`href: ${href}`);
|
18
18
|
console.log(`path:"${pathname}", search:"${search}", hash:"${hash}"`);
|
19
|
-
if( pathname.match(/.(jpg|png|gif|svg)/) ) {
|
19
|
+
if( pathname.match(/.(jpg|png|gif|svg)$/) ) {
|
20
20
|
console.log("img タグが良いっぽい")
|
21
21
|
}
|
22
22
|
else {
|
1
修正
answer
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
現在のブラウザはどれも、 [HTMLAnchorElement](https://developer.mozilla.org/ja/docs/Web/API/HTMLAnchorElement) を介するだけでURL解析できますので、 ``pathname`` の拡張子で切り分ける方法を使えば、複雑な正規表現を書く必要はなくなっています。
|
4
4
|
|
5
|
-
MDN の HTMLAnchorElement の説明にも [HTMLHyperlinkElementUtils](https://developer.mozilla.org/ja/docs/Web/API/HTMLHyperlinkElementUtils) を継承している旨の説明がありますので、例えば以下のような解析例で ``?
|
5
|
+
MDN の HTMLAnchorElement の説明にも [HTMLHyperlinkElementUtils](https://developer.mozilla.org/ja/docs/Web/API/HTMLHyperlinkElementUtils) を継承している旨の説明がありますので、例えば以下のような解析例で ``?cacheBustingNumber``(乱数) 部分を無視した切り分けもできます。
|
6
6
|
|
7
7
|
```javascript
|
8
8
|
var checkURL = ( url ) => {
|
@@ -15,7 +15,13 @@
|
|
15
15
|
// 解析の確認
|
16
16
|
let { href, pathname, search, hash } = a;
|
17
17
|
console.log(`href: ${href}`);
|
18
|
-
console.log(`path:"${pathname}", search:"${search}", hash:"${hash}"`);
|
18
|
+
console.log(`path:"${pathname}", search:"${search}", hash:"${hash}"`);
|
19
|
+
if( pathname.match(/.(jpg|png|gif|svg)/) ) {
|
20
|
+
console.log("img タグが良いっぽい")
|
21
|
+
}
|
22
|
+
else {
|
23
|
+
console.log("a タグが良いっぽい")
|
24
|
+
}
|
19
25
|
|
20
26
|
}
|
21
27
|
checkURL( "https://example.com/path/to/page.html?12345");
|