Javascript 如何在重定向请求中忽略域?
我有3个领域,一个用于开发,另一个用于QA,另一个用于生产。 比如说:Javascript 如何在重定向请求中忽略域?,javascript,jquery,Javascript,Jquery,我有3个领域,一个用于开发,另一个用于QA,另一个用于生产。 比如说: dev-domain.com qa-domain.com prod-domain.com 我想在用户提交电子邮件后将其发送到另一个位置: window.location.href='confirmation.html' 因此,我希望避免在每个环境中执行以下操作: window.location.href='dev domain.com/confirmation.html'或window.location.href='qa
- dev-domain.com
- qa-domain.com
- prod-domain.com
window.location.href='confirmation.html'代码>
因此,我希望避免在每个环境中执行以下操作:
window.location.href='dev domain.com/confirmation.html'
或window.location.href='qa domain.com/confirmation.html'代码>,并且仅执行以下操作:
window.location.href='(测试域)/confirmation.html'代码>
有什么建议吗?文件名.html
应该足够了,因为它是相对路径。您需要实现绝对路径吗?文件名.html
应该足够了,因为它是相对路径。是否需要实现绝对路径?窗口。位置有几个属性,如主机、协议、端口等-
您可以仅更改位置对象的路径:
window.location.pathname = '/confirmation.html';
window.location
有几个属性,如主机、协议、端口等-
您可以仅更改位置对象的路径:
window.location.pathname = '/confirmation.html';
是的,正如前面指出的那样,window.location.hostname
属性返回(当前页面的)internet主机的名称
因此,您可以使用:
window.location.href=window.location.hostname+'/confirmation.html'
是,正如前面指出的那样,window.location.hostname
属性返回(当前页面的)internet主机的名称
因此,您可以使用:
window.location.href=window.location.hostname+'/confirmation.html'
window.location.hostname+'/confirmation.html'
window.location.hostname+'/confirmation.html'