获取URL位置路径名

时间:2013-09-24 15:23:08

标签: url location switch-statement pathname

假设我有一个虚拟网站网址:http://company.com/something

我需要抓住路径:/ something并使用switch case使用javascript重定向到新的URL。

有人可以指导我吗?

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

感谢。

1 个答案:

答案 0 :(得分:0)

我假设您使用的是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);
相关问题