2013-02-07 58 views
-2

我想解析#!/使用Javascript/jQuery的,如网址片段......的JavaScript解析URL

http://www.mydomain.com/#!/home 

将加载

http://www.mydomain.com/home 

谢谢!

+0

只需拆分'url'使用''#,然后加载'0'指数。 –

回答

0
if(location.hash.charAt(1) == "!") location.href = location.hash.substr(2); 

但是更换你的模式,这是一个重定向,这在一定程度违背了#!摆在首位的目的。

也就是说,用局部变量替换location.href,您可以使用它来进行AJAX调用,就像您使用该构造时应该使用的那样。

+0

如何用AJAX调用替换'location.href'? – user2018198

0

由空字符串

var url = "http://www.mydomain.com/#!/home"; 
url = url.replace("#!/",""); 
alert(url) 
0

如果这是你的网址:

var url= "http://www.mydomain.com/#!/home" // window.location.href 
var newUrl = url.substr(0, url.indexOf('#'))+url.substr(url.lastIndexOf('/')+1); 
location.replace(newUrl);