Facebook 喜欢使用 #!在通过ajax加载内容的url中
我正在使用 ajax 加载我的网站的内容。 当我动态加载页面http://www.example.com/a/b/c时 我将当前页面的网址更改为 http//www.example.com/xyz/#!/a/b/c 通过使用 window.location 通过 javascript 设置它
现在我想做的是,当有人输入网址 http/ /www.example.com/xyz/#!/a/b/c 在浏览器中,他应该被定向到 http://www.example.com/a/b/c 而不是 http://www.example.com /xyz/
这与 facebook 上使用的类似 http://www.facebook.com/?ref=logo#!/reqs.php#friend 自动带我去 http://www.facebook.com/reqs.php#friend 当没有ajax加载时。
我尝试使用 javascript 来实现这个,
requestedURL = ""+window.location+"";
position = requestedURL.search("#!");
domainame = "http://localhost"
if(position != -1){
newpage = requestedURL.substr(position+2);
requestedURL = "";
window.location = domainame+newpage;
}
这确实对我有用,但是现在每次当我通过 ajax 加载页面时,这个脚本都会被执行。
有人可以帮我解决这个问题吗? 通过 .htaccess 的解决方案也适合我。
I am using ajax to load content for my site.
When I dynamically load a page http//www.example.com/a/b/c
I change my current page's url to http//www.example.com/xyz/#!/a/b/c by setting it through javascript using window.location
Now what I want to do is that when somebody enters a url http//www.example.com/xyz/#!/a/b/c in the browser, he should be directed to http//www.example.com/a/b/c instead of http//www.example.com/xyz/
This is similar to what is used on facebook
http//www.facebook.com/?ref=logo#!/reqs.php#friend
automatically takes me to
http//www.facebook.com/reqs.php#friend
when loaded without ajax.
I tried using javascript to implement this
requestedURL = ""+window.location+"";
position = requestedURL.search("#!");
domainame = "http://localhost"
if(position != -1){
newpage = requestedURL.substr(position+2);
requestedURL = "";
window.location = domainame+newpage;
}
This did work me but now every time when I load a page even through ajax, this script gets executed.
Can someone help me out with this.
A solution through .htaccess would also do for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来我会尝试从应用程序的路由模块(在服务器端)而不是通过 Ajax 进行模拟。
It looks like something I would try to emulate from the routing module of my application (on the server side) instead of via Ajax.