Skip to content

Instantly share code, notes, and snippets.

@nexeck
Created September 10, 2012 13:38
Show Gist options
  • Save nexeck/3690958 to your computer and use it in GitHub Desktop.
Save nexeck/3690958 to your computer and use it in GitHub Desktop.
Relative URLs in Javascript
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<?php echo URL::Base(); ?>" />
</head>
<body>
<div id="content" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script type="text/javascript">
$.url = function(url) {
return $('base').attr('href')+url.substr(1);
}
$('#content').get($.url('/account/login'));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment