2014年12月12日 星期五

[JS]不一樣的解析網址方式



原文網址:https://gist.github.com/jlong/2428561



簡單舉例:

var parser = document.createElement('a'); 
parser.href = "http://example.com:3000/pathname/?search=test#hash"; 


parser.protocol; // => "http:" 
parser.hostname; // => "example.com" 
parser.port; // => "3000" 
parser.pathname; // => "/pathname/" 
parser.search; // => "?search=test" 
parser.hash; // => "#hash" 
parser.host; // => "example.com:3000"




雖然這樣建立DOM,可能效能上會有點延遲,
但以直覺又快速來寫是個不錯的方法!
筆記下來





沒有留言:

張貼留言