Accessibility Navigation


ImageXY - Mac OS X Batch Photo Resizer

Checkout ImageXY - Painless image resizing for Mac OS X.

Quickly and painlessly bulk resize images, change image formats and create web-friendly photos for your website.

Available on the Mac App Store!

Quick Code: Get the domain name in JS

When your developing a site or online application that uses a lot of XML HTTP Requests (XHR) it’s generally a good idea to use a full URL when creating a request. If you then try to re-use your code across multiple sites and domains, you will find you get errors due to posting to a different domain than the current site.

Solving this problem is easy and will make your Javascript (JS) code more re-usable and easier to manage. All you need to do is create a global variable at the start of your JS file to automagically get the sites domain so you can append it to all your XHR calls.

var DOMAIN = 'http://'+document.domain+'/';

Then just use this variable with all your XHR calls.


About The Author

Jacob Wyke is a web developer from the UK who makes complex things simple on the internet. He develops a batch image resizer for Mac OS X called ImageXY which you should try if you ever need to resize anything for the web.

You should also follow him on twitter.