[英]What is the best way to redirect user to sub-domain(au, nz etc) based on country?
[英]Form to redirect to a sub-domain depending on user input
我需要整理一個表單腳本以根據輸入到表單中的內容來重定向用戶。 我知道這可以通過JavaScript來完成,我設法將某些東西放在一起,但它並沒有完全實現我想要的功能
用戶輸入文本,例如mysubdomain,然后點擊Submit。
然后,我希望將它們轉發到mysubdomain.mydomain.com。 我設法做相反的事情,所以將其定向到mydomain.com/mysubdomain。
你的意思是
<form onsubmit="window.location='http://'+this.subdomain.value+'.mydomain.com/';
return false">
<input type="text" name="subdomain" value="" />
</form>
使用與您所在的域相同的域( 有關此位置對象的詳細信息,請參見MDN ):並假設表單位於xxxx.mydomain.com上
<form
onsubmit="window.location='http://'+
this.subdomain.value+
location.hostname.substring(location.hostname.indexOf('.'))';
return false">
<input type="text" name="subdomain" value="" />
</form>
我認為您可以使用由用戶+您的域重新加載輸入的子域的功能,例如window.location.assign(subdomain + ".yourdomain.com")
還要看看Location對象 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.