javascript - 如何在javascript中进行通配符重定向
问题描述
如何我想在 javascript 中进行通配符重定向。我将此代码放在 index.html 中,但通配符重定向不起作用。当我访问 rootdomain.com 时,它会重定向到 test.example.com 但是当我访问 rootdomain.com/path 时,它不会重定向到 test.example.com/path
<script>
setInterval(function(){
number = document.getElementById("number").innerHTML;
var url1 = 'test.';
var url2 = 'example';
var url3 = '.com';
if (number > 0) {
number--;
}
document.getElementById("number").innerHTML = number;
if (number == 0) {
window.location.replace('https://' + url1 + url2 + url3 + + window.location.pathname);
}
}, 1000);
</script>
我尝试了一个简单的代码,但仍然没有工作:
<script>
window.setTimeout(function(){
// Move to a new location or you can do something else
window.location.href = "https://test.example.com" + window.location.pathname;
}, 5000);
</script>
<h1>Wait 5seconds</h1>
谢谢你
解决方案
试试看:
window.location = 'https://' + url1 + url2 + url3 + window.location.host+window.location.pathname;
推荐阅读
- flutter - 颤振 + Bloc 6.0.6。BlocBuilder 的“builder”回调未提供与“buildWhen”回调相同的状态
- javascript - 有没有办法在这个 algolia 示例代码中使用 async/await?
- spring - spring mongoTemplate 批量查找
- flutter - PageView.animateToPage 不适用于 elasticInOut 动画
- python - 如何使用 Python 添加印度卢比符号?
- javascript - 我想在 discord.js 上进行表情聊天,但出现了问题
- javascript - if 语句在确定井字游戏中的获胜者时不起作用
- r - 如果不同列中存在具有相同组合的值,则删除行
- javascript - TypeError:无法在字符串'/:id'上创建属性'next'
- python - Django不一致的登录行为