Various fixes from Cross browser testing

Fixes implemented while extensively testing CORS support in all modern browsers.

Tested in IE7-IE10, FF 21, Chrome 27, Safari 6.0.4. IE6 doesn't work, and AFAICT never did. Cross domain tested in all browsers except for IE7 (which doesn't support it) and in that case the not supporting cross domain alert worked.