Javascript 单击时重定向到不同存储上的同一页面

Javascript 单击时重定向到不同存储上的同一页面,javascript,Javascript,我正在进行一个Shopify项目,我创建了一个弹出窗口,当页面加载时显示,并要求用户在美国和英国网站之间进行选择 一旦用户点击其中一个选项,弹出窗口要么关闭(英国),要么重定向到美国网站。然后将其存储在cookie中,因此当他们再次访问站点时,会再次重定向/弹出窗口不再显示 代码如下: <div class="modal fade" id="storeModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"

我正在进行一个Shopify项目,我创建了一个弹出窗口,当页面加载时显示,并要求用户在美国和英国网站之间进行选择

一旦用户点击其中一个选项,弹出窗口要么关闭(英国),要么重定向到美国网站。然后将其存储在
cookie
中,因此当他们再次访问站点时,会再次重定向/弹出窗口不再显示

代码如下:

<div class="modal fade" id="storeModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-body">
        <div class="subscription-grid">
          <div class="grid__item">
            <button type="button" class="close" id="subscription-close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
            <div class="store_popup_heading">
              <h2>TEXT</h2>
            </div>
            <div class="store_popup_content">
              <a href="#" class="store-btn" id="uk-store" onClick="checkCookie2();">{{ settings.store_popup_link_text_1 }}</a>
              <a href="#" class="store-btn" id="us-store" onClick="checkCookieUS();">{{ settings.store_popup_link_text_2 }}</a>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<script>
  function checkCookieUS() {
    Cookies.set('storelocation', 'true', {
      expires: 7
    });
    Cookies.set('storelocationUS', 'true', {
      expires: 7
    });
  }
</script>
<script>
  var delayInMilliseconds = 2000
  var storelocate = Cookies.get('storelocation');
  var storeUS = Cookies.get('storelocationUS');

  if (storelocate) {
    document.getElementById("storeModal").style.display = "none";
  } else {
    setTimeout(function() {
      document.getElementById("storeModal").style.display = "block";
    }, delayInMilliseconds);
  }

  if (storeUS) {
    window.location.href = "https://us.store.com/";
  }
</script>
然后重定向到
https://us.store.com/1
例如


有什么办法吗?

您需要获取当前页面的
路径名,并将其附加到
https://us.store.com/

像这样:

if (storeUS){
  window.location = "https://us.store.com" + window.location.pathname;
}

什么是当前的url?也许只需要使用
${window.location.pathname}
if (storeUS){
  window.location = "https://us.store.com" + window.location.pathname;
}