diff options
author | Justin Karneges <justin@affinix.com> | 2013-01-29 15:58:10 -0800 |
---|---|---|
committer | Justin Karneges <justin@affinix.com> | 2013-01-29 15:58:10 -0800 |
commit | c4619ad5b7c2e3a725b480347d55878e9c8abd1c (patch) | |
tree | 930a51cdb0209d4064b3885355bf367ac44f0aa8 | |
parent | fbc1a60edbad95b7408597cba1072dceeb717d56 (diff) | |
download | pollymer-c4619ad5b7c2e3a725b480347d55878e9c8abd1c.tar pollymer-c4619ad5b7c2e3a725b480347d55878e9c8abd1c.tar.gz |
only use json-p on non-cors browsers if not same origin
-rw-r--r-- | polldance.js | 9 |
1 files changed, 8 insertions, 1 deletions
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; |