Skip to content

Instantly share code, notes, and snippets.

@wenzhixin
Last active December 18, 2015 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wenzhixin/5820633 to your computer and use it in GitHub Desktop.
Save wenzhixin/5820633 to your computer and use it in GitHub Desktop.
/**
* var u = url('http://wenzhixin.net.cn:12345/test?name=wenzhixin#about');
* console.log(u.protocol); // http:
* console.log(u.hostname); // wenzhixin.net.cn
* console.log(u.port); // 12345
* console.log(u.pathname); // /test
* console.log(u.search); // ?name=wenzhixin
* console.log(u.hash); // #about
*/
function url(href) {
var a = document.createElement('a');//or document.createElement('area')
a.href = href;
return a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment