Reinstate #2158

PR #2158 fixes an issue where withCredentials must be set after calling open in IE. This change was reverted though.

I did some testing and IE11, Chrome 38 and Firefox 33 do not throw errors if you set withCredentials before calling open. However IE10 will throw an InvalidStateError, preventing this feature from working.

This PR reapplies the patch from #2158 which I have tested in IE11, Chrome 38 and Firefox 33 and does not appear to cause any regressions or warnings, but does fix the InvalidStateError in IE10.

It would be nice to fix this issue in IE10, seeing as I cannot recreate any of the regressions noted in the original PR (unless somebody else can?), so there would appear to be no downsides.

Fixes #2157.