현재 페이지(접속해 있는)의 주소(URL)를 javascript로 알아내기

location.href 또는 document.location.href

 

사용 예>

<script tyle="text/javascript">

<!--

alert(location.href)

//-->

</script>

Posted by 은둔고수

익스플로러(explorer)에서는 location.href가 실행이되는데

파이어폭스(ff : firefox)에서 반응이 없다.

이럴땐 location.replace를 사용한다.

예>수정 전 :

<select name="urlChange" onchange="location.href('http://okkks.tistory.com/');">

  <option name="okkks.tistory.com" value="http://okkks.tistory.com">http://okkks.tistory.com</option>

</select>

수정 후 : <select name="urlChange" onchange="location.replace('http://okkks.tistory.com/');">

Posted by 은둔고수