Posted at 22:52h
in
frontend,
javascript
by heridev
After thinking a little bit I don't remember writing too much about javascript and I really like javascript !!!, well here it is the first post that I want you to share with you guys.
Sometimes you need to get the absolute url from javascript for those cases you can find useful the following function:
[javascript]
window.Utils = {
httpUrlFor: function(url_params) {
var domain, port;
domain = "http://" + window.location.hostname;
port = window.location.port ? ":" + window.location.port : "";
return domain + port + url_params;
}
};
# or in coffee-script
window.Utils =
httpUrlFor: (url_params) ->
domain = "http://#{window.location.hostname}"
port = if window.location.port then ":#{window.location.port}" else ""
"#{domain}#{port}#{url_params}"
[/javascript]