alienhelpdesk.com
projects
Project London
The latest movie directed by Ian Hubert! And I get to help!
usefull sites
mocapdata.com
Free motion capture files!

javascript find root folder

I use this tiny snippet that uses jquery to find the root folder of my website.
It assumes jquery.js is included in the page.
It's usefull for finding out where to post ajax stuff to (so you have a complete root).

For this website it looks in the header of the html for:
<script type="text/javascript" src="http://www.alienhelpdesk.com/js/jquery.js"></script>

  1. // Get the source directory of this script
  2. root = $('script[@src$=jquery.js]').attr('src').replace('js/jquery.js', '');
  3. if(!location.href.match('www')){
  4.         root = root.replace('www.', '');
  5. }
Display clean javascript code for copying
// Get the source directory of this script
root = $('script[@src$=jquery.js]').attr('src').replace('js/jquery.js', '');
if(!location.href.match('www')){
root = root.replace('www.', '');
}
Spanish proverb
Algo es algo, peor es nada
Something is something, nothing is worse
Introducing character animation with Blender
Introducing character animation with Blender
The classic by Tony Mullen
Mastering Blender
Mastering Blender
Excellent read by Tony Mullen