HTMLDOMの場所hrefプロパティ
HTML DOM Location hrefプロパティは、URLパスに対応する文字列を返す/設定します。
構文
以下は構文です-
- hrefの戻り値 プロパティ
location.href
- hrefの値 プロパティセット
location.href = href
例
Location hrefの例を見てみましょう プロパティ-
<!DOCTYPE html>
<html>
<head>
<title>Location href</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>Location-href</legend>
<label for="urlSelect">Current URL:</label>
<input type="url" size="30" id="urlSelect" value="https://www.example.com/aboutUs">
<input type="button" onclick="gethref()" value="Get href">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var urlSelect = document.getElementById("urlSelect");
function gethref(){
divDisplay.textContent = 'URL Path: '+location.href;
}
</script>
</body>
</html> 出力
これにより、次の出力が生成されます-
[hrefを取得]をクリックする前に ボタン-
[hrefを取得]をクリックした後 ボタン-
-
HTMLDOMロケーション検索プロパティ
場所検索プロパティは、URLのクエリパラメータに対応する文字列を返す/設定します。 構文 以下は構文です- 検索の戻り値 プロパティ location.search プロトコルプロパティセットの値 location.search = searchString 例 ロケーション検索の例を見てみましょう プロパティ- <!DOCTYPE html> <html> <head> <title>Location protocol</title> <style> form { &n
-
HTML DOMBasehrefプロパティ
HTML DOM Base hrefプロパティは、HTMLタグに関連付けられています。 タグは、現在のHTMLドキュメント内のすべての相対URLのベースURLを指定するために使用されます。 HTMLドキュメントには最大1つのタグを含めることができます。 Base hrefプロパティは、base要素のhref属性の値を返します。 構文 以下は、-の構文です。 hrefプロパティの設定- baseObject.href = URL ここで、URLはベースURLです。 hrefプロパティを返す- baseObject.href 例 BasehrefPropertyの例を見てみましょう- &