根据用户输入重定向到子域的表单

发布于 2025-01-01 05:43:44 字数 218 浏览 2 评论 0原文

我需要编写一个表单脚本来根据表单中输入的内容重定向用户。我知道这可以通过 JavaScript 来完成,我设法将一些东西放在一起,但它并没有完全达到我想要的效果,即

用户输入文本,例如 mysubdomain,然后点击提交。

然后我希望将它们转发到 mysubdomain.mydomain.com。 我设法做了相反的事情,因此它定向到 mydomain.com/mysubdomain。

I need to put together a form script to redirect the user based on what is entered into the form. I understand this can be done from JavaScript, I managed to put something together but it didn't do quite what I wanted it to do which is

User enters text, for example mysubdomain, then hits submit.

I would then like them to be forwarded to mysubdomain.mydomain.com.
I managed to do the opposite so it directed to mydomain.com/mysubdomain.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

胡大本事 2025-01-08 05:43:44

您的意思是

<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>

Do you mean

<form onsubmit="window.location='http://'+this.subdomain.value+'.mydomain.com/';
 return false">
<input type="text" name="subdomain" value="" />
</form>

using same domain as you are on (details about the location object here at MDN): and assuming the form is on 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>
可是我不能没有你 2025-01-08 05:43:44

我认为您可以有一个功能,可以通过用户+您的域重新加载输入的子域,例如 window.location.assign(subdomain + ".yourdomain.com")

看一下 位置对象

I think you could have a function that reloads the entered subdomain by the user + your domain so like window.location.assign(subdomain + ".yourdomain.com")

Take a look at the Location object as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文