简体   繁体   English

Javascript检测域并重定向

[英]Javascript to detect domain and redirect

I'm hoping someone can help me, this HAS to be possible. 我希望有人可以帮助我,这是有可能的。

My work uses Shopify to run three ecommerce stores for three separate brands. 我的工作使用Shopify为三个不同的品牌经营三个电子商务商店。 To make things easier for many reasons operationally I have merged the three stores into one. 为了简化操作,出于多种原因,我将这三个商店合并为一个。

I need to redirect the existing brand domain names to the appropriate page in the new store. 我需要将现有品牌域名重定向到新商店中的相应页面。 For example www.brandnameone.com.au needs to go to www.shopifystore.com.au/?view=brandnameone 例如,www.brandnameone.com.au需要转到www.shopifystore.com.au/?view=brandnameone

What I'd like to do is detect which domain name the customer is coming from and redirect them. 我想做的就是检测客户来自哪个域名,然后重定向它们。

Is anyone able to help me out with the script beyond 有谁能帮我解决脚本之外的问题

if(document.domain == "brandnameone.com.au")

?

Thanks so much! 非常感谢!

You can do window.location = 'http://URL'; 您可以执行window.location = 'http://URL'; to redirect someone in javascript 重定向JavaScript中的某人

This is pretty trivial. 这很琐碎。 You can use window.location.hostname to get the hostname of the current page ( source ). 您可以使用window.location.hostname获取当前页面的主机名( source )。 and redirect using window.location.replace to redirect ( source ). 并使用window.location.replace进行重定向以进行重定向( )。

switch(window.location.hostname){
   case "brandnameone.com.au":
      window.location.replace("www.shopifystore.com.au/?view=brandnameone");
      break;
   ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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