From c4619ad5b7c2e3a725b480347d55878e9c8abd1c Mon Sep 17 00:00:00 2001 From: Justin Karneges Date: Tue, 29 Jan 2013 15:58:10 -0800 Subject: only use json-p on non-cors browsers if not same origin --- polldance.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/polldance.js b/polldance.js index 2401074..66c76c1 100644 --- a/polldance.js +++ b/polldance.js @@ -42,6 +42,13 @@ var corsAvailable = "withCredentials" in new XMLHttpRequest(); + function sameOrigin(url) { + var loc = window.location; + var a = document.createElement('a'); + a.href = url; + return !a.hostname || (a.hostname == loc.hostname && a.port == loc.port && a.protocol == loc.protocol); + } + var Events = function () { this._events = {}; }; @@ -157,7 +164,7 @@ ++self._tries; if (self.transport == TransportTypes.Auto) { - if (corsAvailable) { + if (corsAvailable || sameOrigin(self._url)) { self.transport = TransportTypes.Xhr; } else { self.transport = TransportTypes.Jsonp; -- cgit v1.2.3