简体   繁体   中英

add path into Current URL Location

I am coding to change language by using Read with Korea Language

Example:

Currently URL is:

http://www.domain.com/EN/index.php

When user press onClick URL change to:

http://www.domain.com/KO/index.php

I mean that I just want to replace EN to KO then reload page again.

Appreciate for your help.

如果您重新加载页面,为什么不使用普通的href。

<a href="http://www.domain.com/KO/index.php">KO</a>

Use the window.location object to get to the new URL:

window.location = window.location.protocol + "//" 
    + window.location.host + window.location.pathname.replace("EN", "KO");

Or I guess simpler, just:

window.location = window.location.href.replace("/EN/", "/KO/");

If you want to load region specific URL check IP filtering for geological locations. Depending upon IP you'll get, load corresponding URL. eg You can use :

 if(ip address coming from <region>)
  window.location.replace("http://www.domain.com/<region>/index.php");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM