使用jQuery或Javascript分割URL [英] splitting the URL using jQuery or Javascript
本文介绍了使用jQuery或Javascript分割URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
URL:
http://testwebsite.com/page1.aspx#page/1
我想使用jQuery或Javascript将URL拆分为aspx,这意味着我想将URL拆分为:
I want to split the URL upto aspx using jQuery or Javascript, meant I want to split the URL so that it should be:
http://testwebsite.com/page1.aspx
我已经尝试过此代码;
I have tried this code;
var url=document.URL;
var arr=url.split('#');
var myoutput=arr[0];
这是正确的分割方式吗?还有其他可靠且更好的方法吗?
Is it the right way to split? Is there any other way which is reliable and better?
推荐答案
您可以只使用location.host + location.pathname
生成特定的页面路径,而不是尝试将字符串拆分为仅包含您想要的内容.
You could just use location.host + location.pathname
to generate the specific page path instead of trying to split down a string to contain only what you want it to.
这篇关于使用jQuery或Javascript分割URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文