teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

改善

2017/04/21 10:01

投稿

spellbound
spellbound

スコア190

title CHANGED
File without changes
body CHANGED
@@ -1,6 +1,21 @@
1
+ # JavascriptでURLから任意の部分だけ取得する方法は?(表題より少し進みました)
2
+ ```html
3
+ <script id="src" type="text/javascript" src="example.js?id=123456789" charset="uft-8"></script>
4
+ ```
5
+ ```javascript
6
+ var src = document.getElementById('src');
7
+ console.log(src.src);
8
+ ```
9
+
10
+ 上記の処理で、「https://example.com/example.js?id=123456789」が取れました。
11
+ 「123456789」だけ欲しいんですが、どうすれば良いでしょうか?
12
+
13
+
1
14
  # 何が分からないのか
2
- ```<script src="example.js?ex=123456789"></script>```
3
15
 
16
+ ```scri
17
+ ```pt src="example.js?ex=123456789"></script>```
18
+
4
19
  上記のコードがHTMLファイル内に記載されていると仮定します。
5
20
 
6
21
  そして、サーバーではなく、クライアント側(Javascript)からURLパラメータを取得したいです。

1

誤植

2017/04/21 10:01

投稿

spellbound
spellbound

スコア190

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,5 @@
1
1
  # 何が分からないのか
2
- ```<script src="example.js?ex="123456789"></script>```
2
+ ```<script src="example.js?ex=123456789"></script>```
3
3
 
4
4
  上記のコードがHTMLファイル内に記載されていると仮定します。
5
5