JavaScript中是否有URL类? [英] Is there URL class in JavaScript?
本文介绍了JavaScript中是否有URL类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在JavaScript中,是否有类似于
In JavaScript, is there any class equivalent for
- iOS SDK中的NSURL类或
- Java中的URL类?
有了这样的课程,我想:
With such class, I want to:
- 规范化URL,
- 从方案,主机,路径组件等组成URL,并且
- 将URL分解为其元素。
推荐答案
James Padolsey解决了这个问题。
James Padolsey had tackled this problem.
简而言之,您可以使用 document.createElement()
创建一个锚元素,并且它的一些原生属性是然后可以轻松访问,例如协议
,端口
和主机名
。
In a nutshell, you can create an anchor element using document.createElement()
, and several of its native properties are then easily accessible, such as protocol
, port
, and hostname
.
更多信息: http://james.padolsey.com/javascript/parsing-urls-with-the-dom/
这篇关于JavaScript中是否有URL类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文