Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there URL class in JavaScript?

Tags:

javascript

url

In JavaScript, is there any class equivalent for

  • NSURL class in iOS SDK or
  • URL class in Java?

With such class, I want to:

  • normalize URL,
  • compose a URL from scheme, host, path components, etc..., and
  • decompose a URL into its elements.
like image 495
torus Avatar asked Nov 20 '12 02:11

torus


1 Answers

James Padolsey had tackled this problem.

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.

For more information: http://james.padolsey.com/javascript/parsing-urls-with-the-dom/

like image 199
Julian H. Lam Avatar answered Sep 29 '22 11:09

Julian H. Lam