Skip to content

Commit

Permalink
Resolves Issue #59: Cross domain CSS files with ? in URL won't load
Browse files Browse the repository at this point in the history
  • Loading branch information
doctyper committed Feb 5, 2012
1 parent fd892e1 commit fcab4d1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
51 changes: 34 additions & 17 deletions cross-domain/respond-proxy.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,37 @@
<body>
<script>
(function () {
var domain, css, url, match, file, ajax, xmlHttp;
var domain, css, query, getQueryString, ajax, xmlHttp;

/*
http://stackoverflow.com/questions/4963673/get-url-array-variables-in-javascript-jquery/4963817#4963817
*/
getQueryString = function() {
var ret = {}, parts, i, p;

parts = (document.location.toString().split("?")[1]).split("&");

for (i = 0; i < parts.length; i++) {

p = parts[i].split("=");
// so strings will be correctly parsed:
p[1] = decodeURIComponent(p[1].replace(/\+/g, " "));

if (p[0].search(/\[\]/) >= 0) { // then it"s an array
p[0] = p[0].replace("[]", "");


if (typeof ret[p[0]] != "object") {
ret[p[0]] = [];
}
ret[p[0]].push(p[1]);
} else {
ret[p[0]] = p[1];
}
}
return ret;
};

ajax = function( url, callback ) {
var req = xmlHttp();
if (!req){
Expand Down Expand Up @@ -52,23 +81,11 @@
};
})();

url = window.location.href;

if (url) {
match = (/css\=(.*\.css)$/).exec(url.slice(url.indexOf('?') + 1));

if (match && match[1]) {
css = match[1];
}

match = (/url\=([^&]+)/).exec(url);

if (match && match[1]) {
domain = match[1];
}
}
query = getQueryString();
css = query["css"];
domain = query["url"];

if (css) {
if (css && domain) {
ajax(css, function (response) {
window.name = response;
window.location.href = domain;
Expand Down
6 changes: 5 additions & 1 deletion cross-domain/respond.proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
urls = [],
refNode;

function encode(url){
return win.encodeURIComponent(url);
}

function fakejax( url, callback ){

var iframe,
Expand All @@ -26,7 +30,7 @@
docElem.insertBefore(iframe, docElem.firstElementChild || docElem.firstChild );
}

iframe.src = checkBaseURL(proxyURL) + "?url=" + redirectURL + "&css=" + checkBaseURL(url);
iframe.src = checkBaseURL(proxyURL) + "?url=" + encode(redirectURL) + "&css=" + encode(checkBaseURL(url));

function checkFrameName() {
var cssText;
Expand Down

0 comments on commit fcab4d1

Please sign in to comment.