首页 > 解决方案 > JavaScript 重定向到基于 URL 的另一个网站

问题描述

使用 JavaScript,如何使其基于 URL 重定向到另一个站点?(示例)如果有人访问https://example.com/12345,它会将他们重定向到https://example.net/12345。如果有人去https://example.com/abc123456,它会将他们重定向到https://example.net/abc123456

我怎样才能做到这一点?

标签: javascripturl

解决方案


您可以为此使用以下代码:

location.href = 'https://example.net/12345';

location.href = 'https://example.net/abc123456';

或为此使用以下代码:

location.replace('https://example.net/12345');

location.replace('https://example.net/abc123456');


推荐阅读