-1

Let's say I have a dummy website URL: http://company.com/something.

I need to grab the path: /something and use a switch case to redirect to a new URL using javascript.

Can someone please guide me?

var URL;
var url_param = location.pathname;

switch(url_param) {
     case "/how-to-do-this":
          URL = '/your-new-destination/';

     default:
          URL: '/thankyou/';

console.log("your new URL is: " + URL);

Thanks.

rolu
  • 378
  • 2
  • 3
  • 19

1 Answers1

0

I assume you're using Javascript

var URL;

switch(window.location.pathname) {
     case "/how-to-do-this":
          URL = '/your-new-destination/';

     default:
          URL= '/thankyou/';
}
console.log("your new URL is: " + URL);
Ruben Serrate
  • 2,724
  • 1
  • 17
  • 21