欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

获取页面当前地址的参数,并将其拼接到要跳转的地址后面。

最编程 2024-10-08 15:18:13
...

源码:

<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>

推荐阅读