Created
February 13, 2017 07:38
-
-
Save emrahoruc/d950e61fff04af41b69ab4a6dbbe6fff to your computer and use it in GitHub Desktop.
URL Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loc(url) { | |
return { | |
search : function() { | |
return url.match(/\?(.+)/i)[1]; | |
}, | |
hash : function() { | |
return url.match(/#(.+)/i)[1]; | |
}, | |
protocol : function() { | |
return url.match(/(ht|f)tps?:/)[0]; | |
}, | |
href : function() { | |
return url.match(/(.+\.[a-z]{2,4})/ig); | |
} | |
} | |
} | |
var l = loc('http://www.net.tutsplus.edu?key=value#hash'); | |
alert(l.href()); // http://www.net.tutsplus.com | |
alert(l.protocol()); // http: | |
alert(l.protocol()); // http: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment