ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻩﺮﺠﻨﭘ ﻥﺎﮑﻣ


فهرست مطالب

    نمایش فهرست مطالب


ﺩﻮﺷ ﻩﺩﺎﻔﺘﺳﺍ ﺖﻓﺎﯾﺭﺩ ﯼﺍﺮﺑ ﺪﻧﺍﻮﺗ ﯽﻣ window.location ﯽﺷ


ﻩﺮﺠﻨﭘ ﻥﺎﮑﻣ

.ﺖﺷﻮﻧ ﻩﺮﺠﻨﭘ ﺪﻧﻮﺸﯿﭘ ﻥﻭﺪﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ window.location

:ﻪﻧﻮﻤﻧ ﺪﻨﭼ

  • window.location.href href (URL) ﯽﻣﺮﺑ ﺍﺭ ﯽﻠﻌﻓ ﻪﺤﻔﺻu20

  • window.location.hostname ﯽﻣﺮﺑ ﺍﺭ ﺏﻭ ﻥﺎﺑﺰﯿﻣ ﻪﻨﻣﺍﺩ ﻡﺎﻧ

  • window.location.pathname ﯽﻣﺮﺑ ﺍﺭ ﯽﻠﻌﻓ ﻪﺤﻔﺻ ﻞﯾﺎﻓ ﻡﺎﻧ

  • window.location.protocol ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻩﺪﺷ ﻩﺩﺎﻔﺘﺳﺍ

  • window.location.assign() ﺪﻨﮐ ﯽﻣ ﯼﺮﯿﮔﺭﺎﺑ ﺍﺭ ﺪﯾﺪﺟ ﺪﻨﺳ


Href ﻩﺮﺠﻨﭘ ﺖﯿﻌﻗﻮﻣ

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﯽﻠﻌﻓ ﻪﺤﻔﺻ 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>

ﻩﺮﺠﻨﭘ ﯽﻧﺎﮑﻣ ﺖﯿﻌﻗﻮﻣ ﻞﮑﺗﻭﺮﭘ

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻪﺤﻔﺻ ﺏﻭ ﻞﮑﺗﻭﺮﭘ 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>

(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>

تمامی حقوق محفوظ است. © BasicIT.org • 2023-2024