2

Script

$(document).ready(function () {
    var referrer = document.referrer;  
    // referrer = http://localhost:49972/Enerji/Kompanzasyon 
    $("#uygula_buton").click(function () {
        if (referrer == "Enerji/Kompanzasyon") {
            //
        }else
        {
            //
        }
    });
});

referrer value is http://localhost:49972/Enerji/Kompanzasyon, But I want to get only controller and action name like this Enerji/Kompanzasyon. How to get this in jquery.

Thanks.

4

3 回答 3

3

尝试

var referrer = "http://localhost:49972/Enerji/Kompanzasyon";

var split = referrer.split("//");

var index = split[1].indexOf("/");​​​  //gets first index of "/" in "localhost:49972/Enerji/Kompanzasyon"

alert(split[1].substring(index+1));

结果 演示在这里

Enerji/Kompanzasyon

​</p>

于 2012-09-15T09:58:28.880 回答
2

Try this,

Live Demo

$(document).ready(function () {
    var referrer = document.referrer;  
    // referrer = http://localhost:49972/Enerji/Kompanzasyon 
    $("#uygula_buton").click(function () {
        ref = referrer.split('/')[3]+"/"+referrer.split('/')[4];
        if (referrer == ref ) {
            //
        }else
        {
            //
        }
    });
});
于 2012-09-15T09:49:45.903 回答
2

您可以在 js 中使用 Split() 函数。

var refer = referrer.split();

并使用refer[2]元素。

于 2012-09-15T09:51:50.367 回答