ﺩﻮﺷ ﻩﺩﺎﻔﺘﺳﺍ ﺖﻓﺎﯾﺭﺩ ﯼﺍﺮﺑ ﺪﻧﺍﻮﺗ ﯽﻣ 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;:ﺖﺳﺍ ﻦﯾﺍ ﻪﺠﯿﺘﻧ
<script>
document.write("Page hostname is " + 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;:ﺖﺳﺍ ﻦﯾﺍ ﻪﺠﯿﺘﻧ
<script>
document.write("Page path is " + 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>
.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻪﺤﻔﺻ ﺏﻭ ﻞﮑﺗﻭﺮﭘ window.location.protocol
:ﺏﻭ ﻞﮑﺗﻭﺮﭘ ﺶﯾﺎﻤﻧ
document.getElementById("demo").innerHTML =
"Page protocol is " + window.location.protocol;:ﺖﺳﺍ ﻦﯾﺍ ﻪﺠﯿﺘﻧ
<script>
document.write("Page protocol is " + 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;:ﺖﺳﺍ ﻦﯾﺍ ﻪﺠﯿﺘﻧ
<script>
document.write("Port number is " + 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>
(https ﯼﺍﺮﺑ 443 ﻭ http ﯼﺍﺮﺑ 80) ﺪﻨﻫﺩ ﯽﻤﻧ ﺶﯾﺎﻤﻧ ﺍﺭ ﺽﺮﻓ ﺶﯿﭘ ﯼﺎﻫ ﺕﺭﻮﭘ ﻩﺭﺎﻤﺷ ﺎﻫﺮﮔﺭﻭﺮﻣ ﺮﺜﮐ
.ﺪﻨﮐ ﯽﻣ ﯼﺮﯿﮔﺭﺎﺑ ﺍﺭ ﺪﯾﺪﺟ ﺪﻨﺳ ﮏﯾ 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>