Tel. 042-353-2371

ÆòÀÏ ¿ÀÀü 9½Ã ~ ¿ÀÈÄ 7½Ã
±â¾÷ÀºÇà

010-8649-6758

¿¹±ÝÁÖ:Á¦ÁÖ»ç¶û(¼ÛÁø¾Æ)
JAVASCRIPT
Ȩ > ȨÆäÀÌÁöÁ¦ÀÛ±³½Ç > JAVASCRIPT

Ä«Å×°í¸® Object
Á¦¸ñ Window > location Object
ÀÛ¼ºÀÚ freewebkorea
ÀÛ¼ºÀÏÀÚ 2009-12-09
Á¶È¸¼ö 1596

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>
ÄÚµå ½ÇÇà Çϱâ