괴발개발/Javascript+JQuery

JS_location객체

moonday 2021. 6. 21. 23:58
더보기

    /*

    - location 객체

      - 웹브라우저의 URL과 관련된 객체

      - http://localhost:5500/day2/location.객체.html?id=abc123#top

      (라이브로 확인할때 ?뒤부터끝까지 주소창에 복붙넣어서 콘솔창 확인하기)

      - hash : 앵커명을 반환, #top

      - host : 주소의 호스트명과 포트번호를 반환

        - http://localhost:5500

      - port : 포트번호, 5500

      - pathname : 경로명, /day2/location객체.html

      - href : 주소값

        - http://localhost:5500/day2/location.객체.html?id=abc123#top

      - protocol : 주소의 트로토콜명을 반환, http:

      - search : 주소의 쿼리 문자열을 반환

    */

  <script>
    console.log('hash : ' +location.hash);
    console.log('host : ' +location.host);
    console.log('port : ' +location.port);
    console.log('pathname : ' +location.pathname); //한글은 인코딩되서 %로나옴
    console.log('href : ' +location.href);
    console.log('protocol : ' +location.protocol);
    console.log('search : ' +location.search);

    //2초 뒤, 네이버로 이동(location.href속성을 이용)
    setTimeout(function(){
      //현재 URL주소를 네이버로 수정
      //location.href = 'http://naver.com';
    },2000);
  </script>

'괴발개발 > Javascript+JQuery' 카테고리의 다른 글

JS_screen객체  (0) 2021.06.21
JS_navigator 객체  (0) 2021.06.21
JS_history객체  (0) 2021.06.21
JS_document객체  (0) 2021.06.21
JS_타이머 기능예제  (0) 2021.06.21