location Object
location Object ¿¡´Â ÇöÀç URL¿¡ ´ëÇÑ Á¤º¸°¡ µé¾î ÀÖ½À´Ï´Ù. URL¿¡ ´ëÇÑ Á¤º¸¶õ ÇöÀç ÆäÀÌÁöÀÇ herf, path, pathname, protocol, host, port µî¿¡ ´ëÇÑ Á¤º¸°¡ µé¾î Àִµ¥, ÀÌ·¯ÇÑ Á¤º¸µéÀ» ¹®ÀÚ¿·Î return ¹ÞÀ» ¼ö ÀÖ½À´Ï´Ù.
location Object ÀÇ Property
| location Object Property |
| Property |
¼³ ¸í |
| hash |
¹®¼³»ÀÇ anchor(href ¼Ó¼º°ª µÚ¿¡ ºÙÀÌ´Â # ¿Í anchor name) name ÁöÁ¤ ¶Ç´Â return |
| host |
¹®¼³»ÀÇ hostname°ú port ¹øÈ£ ÁöÁ¤ ¶Ç´Â return |
| hostname |
¹®¼³»ÀÇ hostname ÁöÁ¤ ¶Ç´Â return |
| href |
Default. Àüü URLÀ» ÁöÁ¤ ¶Ç´Â return. location µÚ¸¦ »ý·«Çϸé location.herf¿Í °°À½. |
| pathname |
hostnameÀ» Á¦¿ÜÇÑ ³ª¸ÓÁö ¹®¼ÀÇ °æ·Î¿Í filename ÁöÁ¤ ¶Ç´Â return |
| port |
URL¿¡¼ »ç¿ëÇÏ´Â port ¹øÈ£ ÁöÁ¤ ¶Ç´Â return |
| protocol |
URL¿¡¼ »ç¿ëµÇ´Â protpcol(http:, ftp: µîµî) ÁöÁ¤ ¶Ç´Â return |
| search |
ÀԷ°ª Àü¼Û°ú °ü·ÃµÈ URL µÚ¿¡ ºÙ´Â ? (¹°À½Ç¥) ÀÌÈÄÀÇ ¹®ÀÚ¿ ÁöÁ¤ ¶Ç´Â return |
location Object ¿¹Á¦ <body>
<a href="http://www.location.net/sample.html#location_object" id="http1">http1</a><br />
<a href="http://www.location.net/doc.asp?filename=search" id="http2">http2</a><br />
<br />
<script type="text/javascript">
<!--
document.write("<b>href</b> : " + location.href + "<br />")
document.write("<b>pathname</b> : " + location.pathname + "<br />")
document.write("<b>protocol</b> : " + location.protocol + "<br />")
document.write("<b>host</b> : " + location.host + "<br />")
document.write("<b>hostname</b> : " + location.hostname + "<br />")
document.write("<b>hash</b> : " + http1.hash + "<br />")
document.write("<b>port</b> : " + http1.port + "<br />")
document.write("<b>search</b> : " + http2.search + "<br />")
// -->
</script>
</body>
location Object Method
location ObjectÀÇ reload() Method ´Â ºê¶ó¿ìÀú â¿¡¼ ¿ìŬ¸¯ ÈÄ ¼±ÅÃÇÏ´Â '»õ·Î °íħ' °ú´Â ´Ù¸¨´Ï´Ù. »õ·Î °íħ(refresh)´Â ¹®¼¿¡¼ »õ·Î °íħÀ» ÇÒ ¶§ÀÇ À§Ä¡¿¡¼ »õ·Î °íħÀÌ µÇÁö¸¸ reload´Â ¹®¼ÀÇ Ã³À½(top)À¸·Î À̵¿ µË´Ï´Ù.
| location Object method |
| Method |
¼³ ¸í |
| reload(boolean) |
| »õ·Î °íħ, ¹®¼¸¦ ´Ù½Ã ÀнÀ´Ï´Ù. |
| false |
Default. ºê¶ó¿ìÀú cache¿¡¼ ´Ù½Ã ÀÐ¾î ¿Â´Ù. |
| true |
¼¹ö¿¡¼ ´Ù½Ã ÀÐ¾î ¿Â´Ù. | |
location Object ¿¹Á¦ <body>
<button onclick="window.location.reload(false)">reload from browser cache</button>
<button onclick="window.location.reload(true)">reload from server</button>
</body>
location Object¸¦ »ç¿ëÇÏ¿© Link °É±â
select - option À¸·Î ¸¸µç drop down boxÀÇ °ªÀº onChange event·Î ¼±ÅÃÇÕ´Ï´Ù. ¾Æ·¡ÀÇ ÄÚµå Áß selectedIndex ´Â drop down box Áß¿¡ ¼±ÅÃµÈ option ElementÀÇ value ¼Ó¼º °ªÀ» ÀǹÌÇÕ´Ï´Ù. ¶ÇÇÑ window.location.href ¿¡¼ ¾ÕÀÇ window¿Í location ObjectÀÇ Default °ªÀÎ href ´Â »ý·« °¡´ÉÇÕ´Ï´Ù.
Source code
<body>
<select onchange="window.location.href=this.options[this.selectedIndex].value">
<option>°Ë»ö »çÀÌÆ®</option>
<option value="http://kr.yahoo.com/">yahoo</option>
<option value="http://www.naver.com/">naver</option>
<option value="http://www.empas.com/">empas</option>
</select>
</body>