源码:
<div>
<button onclick="currentToRegister()">当前页面带参跳转</button>
<button onclick="newToRegister()">新页面带参跳转</button>
</div>
<script>
// 在当前页面携带当前路径参数跳转
function currentToRegister(){
const queryParams = window.location.search;
window.location.href = 'https://www.baidu.com/' + queryParams;
}
// 在新页面携带当前路径参数跳转
function newToRegister(){
const queryParams2 = window.location.search;
const newUrl = 'https://www.baidu.com/' + queryParams2;
window.open(newUrl, '_blank', 'noopener');
}
</script>