반응형

Google, Location History - https://www.google.com/maps/timeline?pb

간만에 들어가봤더니 살면서 가본 곳이 중국,일본뿐이구나. 신혼여행 필리핀.

반응형
반응형

[javascript] 현재 경로를 찾아서 어느 위치인지 인식한다.

 

 

   //-- 현재 url 호출
    var now_path_nm = location.pathname;

 

  //-- 현재 url에 찾고 있는 문자가 있으면 -1 보다 큰 숫자 리턴
    var result = now_path_nm.indexOf("s");

반응형
반응형

JavaScript에서의 location.href 와 location.replace 의 차이점


자바스크립트에서 페이지 이동 시킬때 location.href를 많이 사용하지만 location.replace 메세드도 종종 이용된다.
두가지 모두 같은 동작을 하는거 같지만 실제로는 아래와 같은 차이점이 있다.

location.href는 객체의 속성이며, loaction.replace()는 메서드(함수)로 작동된다.
href는 페이지를 이동하는 것이기 때문에 뒤로가기 버튼을 누른경우 이전 페이지로 이동이 가능하지만,
replace는 현재 페이지를 새로운 페이지로 덮어 씌우기 때문에 이전 페이지로 이동이 불가능하다.

href는 일반적인 페이지 이동시 이용을 하면 되고,
replace의 경우는 이전페이지로 접근이 필요없는경우 보안상 덮어씌우는 것도 괜찮을듯 하다.

location.href Method

Including the following script will immediately redirect visitors to the URL entered.

<script type="text/javascript">
     location.href='http://www.bloggingdeveloper.com';
</script>
 

location.replace Method

Including the following script will immediately redirect visitors to the URL entered.

<script type="text/javascript">
     location.replace('http://www.bloggingdeveloper.com/');
</script>

The difference between location.href and location.replace

The difference between location.href and location.replace is that the former creates a new history entry on the visitor's browser meaning that if they hit the back button, they can get in a 'redirection loop' which is usually undesirable and may have unwanted side effects.

반응형

+ Recent posts