ﺩﻮﺷ ﻩﺩﺎﻔﺘﺳﺍ ﺖﻓﺎﯾﺭﺩ ﯼﺍﺮﺑ ﺪﻧﺍﻮﺗ ﯽﻣ window.location
ﯽﺷ
.ﺖﺷﻮﻧ ﻩﺮﺠﻨﭘ ﺪﻧﻮﺸﯿﭘ ﻥﻭﺪﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ window.location
ﯽ
:ﻪﻧﻮﻤﻧ ﺪﻨﭼ
window.location.href
href (URL) ﯽﻣﺮﺑ ﺍﺭ ﯽﻠﻌﻓ ﻪﺤﻔﺻu20
window.location.hostname
ﯽﻣﺮﺑ ﺍﺭ ﺏﻭ ﻥﺎﺑﺰﯿﻣ ﻪﻨﻣﺍﺩ ﻡﺎﻧ
window.location.pathname
ﯽﻣﺮﺑ ﺍﺭ ﯽﻠﻌﻓ ﻪﺤﻔﺻ ﻞﯾﺎﻓ ﻡﺎﻧ
window.location.protocol
ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻩﺪﺷ ﻩﺩﺎﻔﺘﺳﺍ
window.location.assign()
ﺪﻨﮐ ﯽﻣ ﯼﺮﯿﮔﺭﺎﺑ ﺍﺭ ﺪﯾﺪﺟ ﺪﻨﺳ
.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﯽﻠﻌﻓ ﻪﺤﻔﺻ code class="w3-codespan">window.location.href URL> ﯽ
:ﯽﻠﻌﻓ ﻪﺤﻔﺻ href (URL) ﺶﯾﺎﻤﻧ
document.getElementById("demo").innerHTML =
"Page location is " + window.location.href;
:ﺖﺳﺍ ﻦﯾﺍ ﻪﺠﯿﺘﻧ
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript</h2>
<h3>The window.location object</h3>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"The full URL of this page is:<br>" + window.location.href;
</script>
</body>
</html>
.ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ (ﯽﻠﻌﻓ ﻪﺤﻔﺻ) ﯽﺘﻧﺮﺘﻨﯾﺍ ﻥﺎﺑﺰﯿﻣ ﻡﺎﻧ window.
:ﻥﺎﺑﺰﯿﻣ ﻡﺎﻧ ﺶﯾﺎﻤﻧ
document.getElementById("demo").innerHTML =
"Page hostname is " + window.location.hostname;
:ﺖﺳﺍ ﻦﯾﺍ ﻪﺠﯿﺘﻧ
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript</h2>
<h3>The window.location object</h3>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"Page hostname is: " + window.location.hostname;
</script>
</body>
</html>
ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ ﺮﯿﺴﻣ ﻡﺎﻧ window.location.pathname
:ﯽﻠﻌﻓ URL ﺮﯿﺴﻣ ﻡﺎﻧ ﺶﯾﺎﻤﻧ
document.getElementById("demo").innerHTML =
"Page path is " + window.location.pathname;
:ﺖﺳﺍ ﻦﯾﺍ ﻪﺠﯿﺘﻧ
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript</h2>
<h3>The window.location object</h3>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"Page path is: " + window.location.pathname;
</script>
</body>
</html>
.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻪﺤﻔﺻ ﺏﻭ ﻞﮑﺗﻭﺮﭘ :ﺏﻭ ﻞﮑﺗﻭﺮﭘ ﺶﯾﺎﻤﻧ :ﺖﺳﺍ ﻦﯾﺍ ﻪﺠﯿﺘﻧ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ ﺖﻧﺮﺘﻨﯾﺍ ﻥﺎﺑﺰﯿﻣ ﻩﺭﺎﻤﺷ :ﻥﺎﺑﺰﯿﻣ ﻡﺎﻧ ﺶﯾﺎﻤﻧ :ﺖﺳﺍ ﻦﯾﺍ ﻪﺠﯿﺘﻧ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ (https ﯼﺍﺮﺑ 443 ﻭ http ﯼﺍﺮﺑ 80) ﺪﻨﻫﺩ ﯽﻤﻧ ﺶﯾﺎﻤﻧ ﺍﺭ ﺽﺮﻓ ﺶﯿﭘ ﯼﺎﻫ ﺕﺭﻮﭘ ﻩﺭﺎﻤﺷ ﺎﻫﺮﮔﺭﻭﺮﻣ ﺮﺜﮐ .ﺪﻨﮐ ﯽﻣ ﯼﺮﯿﮔﺭﺎﺑ ﺍﺭ ﺪﯾﺪﺟ ﺪﻨﺳ ﮏﯾ :ﺪﯾﺪﺟ ﺪﻨﺳ ﮏﯾ ﯼﺭﺍﺬﮔﺭﺎﺑ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧwindow.location.protocol
ﻝﺎﺜﻣ
document.getElementById("demo").innerHTML =
"Page protocol is " + window.location.protocol;
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript</h2>
<h3>The window.location object</h3>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"The page protocol is: " + window.location.protocol;
</script>
</body>
</html>
ﻩﺮﺠﻨﭘ ﯽﺑﺎﯾ ﺖﯿﻌﻗﻮﻣ ﻩﺎﮔﺭﺩ
window.location.po
ﻝﺎﺜﻣ
document.getElementById("demo").innerHTML =
"Port
number is " + window.location.port;
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript</h2>
<h3>The window.location object</h3>
<p id="demo"></p>
<p><b>Note: </b>If the port number is default (80 for http and 443 for https), most browsers will display 0 or nothing.</p>
<script>
document.getElementById("demo").innerHTML =
"The URL port number of the current page is: " + window.location.port;
</script>
</body>
</html>
ﻩﺮﺠﻨﭘ ﯽﻧﺎﮑﻣ ﺖﯿﻌﻗﻮﻣ ﻦﯿﯿﻌﺗ
window.location.assign()
ﻝﺎﺜﻣ
<html>
<head>
<script>
function newDoc() {
window.location.assign("https://www.w3schools.com")
}
</script>
</head>
<body>
<input type="button" value="Load new document"
onclick="newDoc()">
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript</h2>
<h3>The window.location object</h3>
<input type="button" value="Load new document" onclick="newDoc()">
<script>
function newDoc() {
window.location.assign("https://www.w3schools.com")
}
</script>
</body>
</html>