- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <!-- 현재 작성하고 있는 파일은 UTF-8 DOS파일입니다.-->
- <html xmlns="http://www.w3.org/1999/xhtml" lang="ko">
- <head>
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
- </head>
- <body>
- <div id="ex_js_syntax">
- <script type="text/javascript" language="javascript">
- <!--
- function location_href(){
- /* 로케이션 현재 URL 정보 출력 => location.href */
- /* hash[책갈피], host, hostname, pathname, port, protocol, search 등의 속성으로
- 정보 출력해주는 기능이 있지만...자주 안쓸것 같아서 생략 */
- document.getElementById("location_href").innerHTML = location.href;
- }
- function location_href_url(){
- /* 로케이션 원하는 URL 이동(http://www.daum.net) =>
- location.href="이동할URL" ※히스토리 기록이 남습니다.
- 같은 기능으로 location.assign("이동할URL")함수가 있습니다. */
- var link_url = "http://www.daum.net";
- location.href = link_url;
- // 위와 같은 기능 함수 location.assign(link_url);
- document.getElementById("location_href_url").innerHTML = link_url;
- }
- //-->
- </script>
- <form name="input_type" id="input_type" method="post" >
- <!-- 예제 박스에선 안됨 => form태그안에 form태그있으면 지워짐~ㅠ.ㅠ -->
- 로케이션 기능1 => 현재 URL 정보 출력 <br />
- <p id="location_href" onclick="location_href();">location객체 링크정보[클릭]</p>
- 로케이션 기능2 => 원하는 URL 이동(http://www.daum.net) 히스토리 기록 <br />
- <p id="location_href_url" onclick="location_href_url();">location객체 링크이동[클릭]</p>
- </form>
- </div>
- </body>
- </html>
--------------------------------------------------------------------------------------------
위 소스 예제 보기
기능 1=> 로케이션 현재 URL 정보 출력 => location.href;
기능 2=> 로케이션 원하는 URL 이동(http://www.daum.net) => location.href="이동할URL";
※히스토리에 현재 페이지의 URL이 기록이 남습니다.
같은 기능으로 location.assign("이동할URL")함수가 있습니다
기능 1과 같은 URL 정보 출력 속성 설명
hash[책갈피], host, hostname, pathname, port, protocol, search 등의 속성으로
정보 출력해주는 기능이 있지만...
자주 안쓸것 같아서 생략하며, 자세한 내용은 위 링크에서 보시기 바랍니다.
출처 & 인용 - http://www.w3schools.com/
'javascript > Location()객체' 카테고리의 다른 글
Location객체 reload() 새로고침 (0) | 2014.02.07 |
---|---|
Location객체 replace() 원하는 URL 이동[히스토리기록 안함] (0) | 2014.02.07 |