🌐
EncodedNA
encodedna.com › javascript › redirect-to-another-page-with-multiple-parameters-in-javascript.htm
How to Redirect to another Page with Multiple Parameters in JavaScript
May 20, 2025 - Now, to insert multiple parameters to the URL, you’ll have to define parameters with values using the ? (Question mark) and & (ampersand) symbols before redirecting. For example, &ltscript> let redirectPage = () => { const url = "https://www yourwebsite com/content/ocncontent?userid=43&c...
🌐
Bobby Hadz
bobbyhadz.com › blog › redirect-to-another-page-with-parameters-using-javascript
Redirect to another Page with Parameters using JavaScript | bobbyhadz
March 7, 2024 - Set the window.location.href property to redirect to the page with parameters. Here is the HTML for the example. ... Copied!<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> </head> <body> <h2>bobbyhadz.com</h2> <button ...
Discussions

jquery - Redirect to another page and pass parameter via JavaScript - Stack Overflow
I have been trying to pass parameter in a ASP.NET page to another page (in our web site) by redirecting using JavaScript (or jQuery, Ajax, Fetch, etc.) and catch this parameter on Load event of the More on stackoverflow.com
🌐 stackoverflow.com
javascript - How to redirect to an html page with parameters? - Stack Overflow
I have two HTML pages running on a localhost server and would like for the first page to redirect to the other one but with parameters so that I can use queries on the second page. This is my code in More on stackoverflow.com
🌐 stackoverflow.com
javascript - How do I redirect to another webpage? - Stack Overflow
How can I redirect the user from one page to another using jQuery or pure JavaScript? More on stackoverflow.com
🌐 stackoverflow.com
How do I redirect with JavaScript? - Stack Overflow
How do you redirect to a page from another page with JavaScript? More on stackoverflow.com
🌐 stackoverflow.com
🌐
ASPSnippets
aspsnippets.com › Articles › 2793 › Redirect-to-another-Page-with-multiple-Parameters-using-JavaScript
Redirect to another Page with multiple Parameters using JavaScript
May 3, 2019 - The multiple values to be passed to another Page will be added to the URL as QueryString parameters and then the Page will be redirected to another Page using window.location property in JavaScript.
🌐
Talkerscode
talkerscode.com › howto › how-to-redirect-to-another-page-in-javascript-with-parameters.php
How To Redirect To Another Page In JavaScript With Parameters
<html> <head> </head> <script> ... B, simply enter URL B here, as demonstrated in the example above. Setting the href attribute of the window.location object is the most popular approach to redirect a URL in JavaScri...
🌐
EncodedNA
encodedna.com › javascript › how-to-redirect-page-using-javascript.htm
How to Redirect to another page using JavaScript
The URL of a webpage can have parameters. So, here’s how you can do this. &ltscript> let redirectPage = () => { window.open("https://www.encodedna.com/?pg=2", "_blank"); } &lt/script> ... Note: If you want, you can add multiple parameters to the redirect URL.
🌐
ScratchCode
scratchcode.io › home › redirect by javascript with example
Redirect By JavaScript With Example | Scratch Code
June 15, 2021 - In the above example, we are fetching the browser name using the navigator.appName and based on the browser’s name we are redirecting to the appropriate page. Usually, we want to pass additional details with the URL which we have known as parameters or query strings. If you would like to pass some parameters with URL redirect in JavaScript then use the following code.
🌐
W3Schools
w3schools.com › howto › howto_js_redirect_webpage.asp
How To Redirect to Another Webpage
There are a couple of ways to redirect to another webpage with JavaScript.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-redirect-to-another-webpage-using-javascript
How to Redirect to Another Webpage using JavaScript? | GeeksforGeeks
October 25, 2024 - The window location href property is used to set or return the complete URL of the current page. The Location href property can also be used to set the href value point to another website or point to an email address.
🌐
Sentry
sentry.io › sentry answers › javascript › redirect to another page using javascript
Redirect to Another Page Using JavaScript | Sentry
if (api.response.success) { // Redirect to success page window.location.replace("https://yourdomain.com/success"); } else { // Show API response error message } This solution may not be ideal for something like a mailing list landing page, or any page where it’s important to preserve the “back” button’s behavior, as this will replace the user’s history. To preseve the “back” button behavior, rather use assign(). Capture and report JavaScript errors with window.onerror
🌐
TutorialsPoint
tutorialspoint.com › how-to-redirect-to-another-webpage-using-javascript
How to redirect to another webpage using JavaScript?
April 20, 2022 - When you click on the “Redirect Me” button, it will redirect to the new web page. The location.replace(url) method can be used to replace the current webpage with another webpage loaded from the url. We can use the following syntaxes to redirect −
🌐
Wisepops
support.wisepops.com › all collections › advanced › dynamically add a custom parameter to a redirect url
Dynamically Add a Custom Parameter to a Redirect URL | Help center
We can add custom parameters on the fly to a redirect URL through the Wisepops' JS callbacks feature · Let's say we want to redirect our visitors that click on a CTA to https://example.com/ with a dynamic GET parameter year. For example, during the year 2020, the CTA should redirect to ...
🌐
Love2Dev
love2dev.com › blog › ways-to-use-javascript-redirect-to-another-page
4 Ways JavaScript Can Redirect Or Navigate To A Url Or Refresh The Page 🔀
The window.location has multiple methods to help you refresh, reload and change the current page. You can use this techique from your JavaScript to trigger page updates.
🌐
Java67
java67.com › 2017 › 07 › 6-ways-to-redirect-web-page-using-JavaScript-and-jQuery.html
5 ways to redirect a web page using JavaScript and jQuery | Java67
On the client-side, the redirection client is responsible for routing requests to another URL but in server-side redirection, it's the server's job to redirect to a new page. JQuery and JavaScript are mostly used for client-side redirection and there are a number of ways to redirect a web page using JavaScript In this tutorial, we'll examine some of the most popular and common ways to redirect a web page using JavaScript and jQuery.
🌐
Stack Abuse
stackabuse.com › javascript-how-to-redirect-to-another-webpage
JavaScript: How to Redirect to Another Webpage
August 5, 2025 - You send users to other pages correlated with the content of the current site. All of these are practically achieved through the Location object that contains URL information. There are a few ways to do this, by fiddling around with different properties of the Location object. In this tutorial, we'll take a look at how to redirect a user to a different webpage in JavaScript and what to look out for to minimize the potential negative SEO impact.
Top answer
1 of 2
1

You can get the URL via JS very easily.

You have not provided the button click code in the question. So I am assuming there can be two ways to be redirected to another page;

  1. You can add a button and write a click function to redirect;

    <button onclick="redirect()"> Go To Page 2 </button>
    <script>
    function redirect()
    {
        var currentUrl = window.location.href;
        var parts = currentUrl.split("/");
        var param = parts[parts.length() -  1];
        window.location.hef = page2_url + "/" + param;
    }
    </script>
    
  2. You can also add an anchor tag for redirection;

    <a href="page2_url" id="redirectlink"> Button </a>
    <script>
      (function(){
          var currentUrl = window.location.href;
          var parts = currentUrl.split("/");
          var param = parts[parts.length() -  1];
    
          $("#redirectlink").attr("href", "page2_url" + "/" + param)
     })()
    </script>
    
2 of 2
0

You can use window.location.href to get the current URL of the page you're on. This will be stored as a string. You can then use .split('/') to turn your string into an array of parameters (where each index is split based on a /).

Eg:

"page.com/page1/food".split('/')

will yield:

const params = ["page.com", "page1", "food"]

To get the last element of this array you can use params.length-1 as the index, and then append this retrieved value onto the end of your redirected page. To redirect you set window.location.href equal to the new url.

See working example below:

$('#redirect').click(function() {
  const url = window.location.href; // 'https://stacksnippets.net/js'
  const params = url.split('/'); // ['https', '', 'stacksnippets.net', 'js']
  const parameter = params[params.length-1]; // 'js'
  
  const page2 = "https://www.example.com/" +parameter; // 'https://www.example.com/js'
  alert("Going to new page: " +page2);
  window.location.href = page2 // Go to page2 url
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="redirect">Click me</button>