0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

다국어 사이트 이동 조금 꼼수를 부려서 해결함

Posted at

현재 url 을 알아내서 문자열 대체후 원하는 url로 이동하기

요즘 일이 너무 없어서 검도 관련 자료를 알아보고 있었는데
거의 3달만에 일 시킴
다국어 사이트가 있는데 그건도 드림위버로 만들었는지 템플릿에서 수정한면 파일들이 수정됨
이제껏 프로젝트 하면서 이런 종류의 작업은 거의 하지 않았지만

2시간정도 고민함
현재 url 을 알아내서 현재 url 의 문자열을 대체한뒤 url 이동이 중요포인트

qiita.rb
<ul>
   <li class="current guide"><a href="javascript:void(0)" class="btn-lang">日本語-</a></li>
   <li class="eng guide_eng"><a href="javascript:void(0)" class="btn-lang">English</a></li>
   <li class="chi guide_chi"><a href="javascript:void(0)" class="btn-lang">中文</a></li>
   <li class="kor guide_kor"><a href="javascript:void(0)" class="btn-lang">한국</a></li>
   <li class="easy"><a href="../guide_easy/index.html">やさしい日本語</a></li>
</ul>
qiita.rb

$(function(){

  function langChg() {
  
    var langBtn = $('.btn-lang'); // 버튼에 적용할 class
    var currentUrl = window.location.href; // 현재 url 을 알아낸다
    var currentPath = window.location.pathname.split("/")[1]; // 첫벗째 슬러값뒤의 문자열을 알아낸다
    
    langBtn.on('click', function(){
      
      //japanese 현재 클릭된 부모의 guide 클래스를 가지고 있는경우
      if ($(this).parent('li').hasClass('guide')) {
        //현재 url을 알아내서 currentPath로 알아낸 값을 대체한다
        var newPath = currentUrl.replace(currentPath,"guide");
        //url 이동
        location.href = newPath;

        console.log(newPath);
      }
      //english
      if ($(this).parent('li').hasClass('guide_eng')) {
        var newPath = currentUrl.replace(currentPath,"guide_eng");
        location.href = newPath;
      }
      //chiinese
      if ($(this).parent('li').hasClass('guide_chi')) {
        var newPath = currentUrl.replace(currentPath,"guide_chi");
        location.href = newPath;        
      }
      //korean
      if ($(this).parent('li').hasClass('guide_kor')) {
        var newPath = currentUrl.replace(currentPath,"guide_kor");
        location.href = newPath;        
      }                  
    })
  }  
  langChg() //함수실행
})
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?