URL¼´Í³Ò»×ÊÔ´¶¨Î»·û (Uniform Resource Locator, URL)£¬ÍêÕûµÄURLÓÉÕ⼸¸ö²¿·Ö¹¹³É£º
scheme://host:port/path?query#fragment
scheme:ͨÐÅÐÒ飬³£ÓõÄhttp,ftp,maitoµÈ¡£
host:Ö÷»ú£¬·þÎñÆ÷(¼ÆËã»ú)ÓòÃûϵͳ (DNS) Ö÷»úÃû»ò IP µØÖ·¡£
port:¶Ë¿ÚºÅ£¬ÕûÊý£¬¿ÉÑ¡£¬Ê¡ÂÔʱʹÓ÷½°¸µÄĬÈ϶˿ڣ¬ÈçhttpµÄĬÈ϶˿ÚΪ80£¬httpsµÄĬÈ϶˿ÚÊÇ443¡£
path:·¾¶£¬ÓÉÁã»ò¶à¸ö"/"·ûºÅ¸ô¿ªµÄ×Ö·û´®£¬Ò»°ãÓÃÀ´±íʾÖ÷»úÉϵÄÒ»¸öĿ¼»òÎļþµØÖ·¡£
query:²éѯ£¬¿ÉÑ¡£¬ÓÃÓÚ¸ø¶¯Ì¬ÍøÒ³£¨ÈçʹÓÃCGI¡¢ISAPI¡¢PHP/JSP/ASP/ASP.NETµÈ¼¼ÊõÖÆ×÷µÄÍøÒ³£©´«µÝ²ÎÊý£¬¿ÉÓжà¸ö²ÎÊý£¬ÓÃ"&"·ûºÅ¸ô¿ª£¬Ã¿¸ö²ÎÊýµÄÃûºÍÖµÓÃ"="·ûºÅ¸ô¿ª¡£
fragment:ÐÅϢƬ¶Ï£¬×Ö·û´®£¬ÓÃÓÚÖ¸¶¨ÍøÂç×ÊÔ´ÖеÄƬ¶Ï¡£ÀýÈçÒ»¸öÍøÒ³ÖÐÓжà¸öÃû´Ê½âÊÍ£¬¿ÉʹÓÃfragmentÖ±½Ó¶¨Î»µ½Ä³Ò»Ãû´Ê½âÊÍ¡£(Ò²³ÆΪêµã)Õâ¸ö±êÖ¾µã²»ÊÇͳһ×ÊÔ´±êÖ¾·ûµÄÒ»²¿·Ö£¬¶øÊÇÈÃÓû§ä¯ÀÀÆ÷ÔÚ»ñµÃÁËÎļþºóÀ´µ¼º½Óõģ¬Òò´ËËüʵ¼ÊÉϲ»±»Ë͵½·þÎñÆ÷¡£
ÏÂÃæÎÒÃǾÙÀýÒ»¸öURL£¬È»ºó»ñµÃËüµÄ¸÷¸ö×é³É²¿·Ö¡£
http://bbs.aseoe.com/forum.php?gid=42
window.location.href ¿ÉÒÔ»ñµÃÕû¸öURL×Ö·û´®£¨ÔÚä¯ÀÀÆ÷ÖоÍÊÇÍêÕûµÄµØÖ·À¸£©¡£
var test = window.location.href;
alert(test);
³ÌÐò·µ»Øhttp://bbs.aseoe.com/forum.php?gid=42
window.location.protocol ¿ÉÒÔ»ñµÃ URL µÄÐÒ鲿·Ö
var test = window.location.protocol;
alert(test);
³ÌÐò·µ»Ø http:
window.location.host ¿ÉÒÔ»ñµÃ URL µÄÖ÷»ú²¿·Ö
var test = window.location.host;
alert(test);
³ÌÐò·µ»Ø bbs.aseoe.com
window.location.port ¿ÉÒÔ»ñµÃ URL µÄ¶Ë¿Ú²¿·Ö
var test = window.location.port;
alert(test);
Èç¹û²ÉÓÃĬÈϵÄ80¶Ë¿Ú(update:¼´Ê¹Ìí¼ÓÁË:80)£¬ÄÇô·µ»ØÖµ²¢²»ÊÇĬÈϵÄ80¶øÊÇ¿Õ×Ö·û¡£
window.location.pathname »ñµÃ URL µÄ·¾¶²¿·Ö£¨¾ÍÊÇÎļþµØÖ·£©
var test = window.location.pathname;
alert(test);
window.location.search »ñµÃ²éѯ£¨²ÎÊý£©²¿·Ö£¬³ýÁ˸ø¶¯Ì¬ÓïÑÔ¸³ÖµÒÔÍ⣬ÎÒÃÇͬÑù¿ÉÒÔ¸ø¾²Ì¬Ò³Ã棬²¢Ê¹ÓÃjavascriptÀ´»ñµÃÏàÐÅÓ¦µÄ²ÎÊýÖµ¡£
var test = window.location.search;
alert(test);
window.location.hash »ñµÃêµã¡£
var test = window.location.hash;
alert(test);
±¾Õ¾»¶ÓÈκÎÐÎʽµÄתÔØ£¬µ«ÇëÎñ±Ø×¢Ã÷³ö´¦£¬×ðÖØËûÈËÀͶ¯³É¹û
תÔØÇë×¢Ã÷£º ÎÄÕÂתÔØ×Ô£º°®Ë¼×ÊÔ´Íø http://www.aseoe.com/show-12-93-1.html
תÔØÇë×¢Ã÷£º ÎÄÕÂתÔØ×Ô£º°®Ë¼×ÊÔ´Íø http://www.aseoe.com/show-12-93-1.html