javascript - JavaScript 重定向到基于 URL 的另一个网站
问题描述
使用 JavaScript,如何使其基于 URL 重定向到另一个站点?(示例)如果有人访问https://example.com/12345,它会将他们重定向到https://example.net/12345。如果有人去https://example.com/abc123456,它会将他们重定向到https://example.net/abc123456
我怎样才能做到这一点?
解决方案
您可以为此使用以下代码:
location.href = 'https://example.net/12345';
location.href = 'https://example.net/abc123456';
或为此使用以下代码:
location.replace('https://example.net/12345');
location.replace('https://example.net/abc123456');
推荐阅读
- c# - 从 LDAP 中的域列表中识别子域
- php - varchar 中的 OrderBy 包含整数
- jenkins - 詹金斯插件来排队工作
- python-3.x - channel.start_sumption() 没有运行并且没有提供任何异常
- javascript - 使用锚点导航而不更改浏览器 url 和 javascript
- oracle - SQL*Loader 控制文件将一个数据字段映射到两列
- css - 如何将图像大小调整为 100 像素宽度和 100 像素高度?
- python - 递归组合字典
- javascript - 如何让我的 chrome 扩展记住切换开关或其他操作?
- mysql - Mysql兼容的内存数据库中的查询错误(h2)