将URL分解为其组件 [英] Break a URL into its components
问题描述
我正在使用javascript并希望获取我拥有的URL字符串并将其分解为其组件,例如主机,路径和查询参数。
<我需要这样做才能获得一个查询参数,它本身就是一个URL,因此用原始的URL字符串编码。
我觉得就像在Javascript中应该有一个简单的方法来做到这一点。也许看起来像这样:
var what_I_Want = url(http://www.domain.com?queryArg1=somequeryargument ).getQueryArgumentValue( queryArg1\" );
parseUri 功能将完成您需要的一切
编辑
另外,您可以让DOM为您的辛勤工作并访问属性在新创建的 a
对象上,用于URL的不同部分。
I'm using javascript and would like to take a URL string that I have and break it down into its components such as the host, path, and query arguments.
I need to do this in order to get to one of the query arguments, which is itself a URL and is thus encoded in the original URL string.
I feel like there should be an easy way to do this in Javascript. Perhaps something that looks like this:
var what_I_Want = url("http://www.domain.com?queryArg1=somequeryargument").getQueryArgumentValue("queryArg1");
The parseUri function will do everything you need
Edit
Alternatively you can get the DOM to do the hard work for you and access properties on a newly created a
object for different parts of the URL.
这篇关于将URL分解为其组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!