如何从URl获取特定字符串?

时间:2013-04-14 20:08:46

标签: jquery

大家好我有一个看起来像这样的URL

       http://localhost:60255/Roles/12/Users/

我需要从窗口中使用jquery从href获取此内容,我应该得到此字符串

       http://localhost:60255/Roles/ 
来自点击事件网址的

    this is what i had been trying

      var windowpathname = window.location.pathname; window.location.href = windowpathname + "Roles/" + RoleID + "/" + RoleName;   

在这种情况下,当我第二次点击时

       http://localhost:60255/Roles/12/Rahul/Roles/14/Kishore/

2 个答案:

答案 0 :(得分:0)

对象window.location的一些属性:

hash: ""
host: "fiddle.jshell.net"
hostname: "fiddle.jshell.net"
href: "http://fiddle.jshell.net/_display/"
origin: "http://fiddle.jshell.net"
pathname: "/_display/"

答案 1 :(得分:0)

你可以试试这个

window.location.href = window.location.hostname + "/Roles/" + RoleID + "/" + RoleName;