Skip to content

Commit b21c578

Browse files
author
Scott Jehl
committed
Merge pull request #104 from scottjehl/cross-domain
Resolves Issue #59: Cross domain CSS files with ? in URL won't load
2 parents ed8479c + f949305 commit b21c578

File tree

2 files changed

+43
-23
lines changed

2 files changed

+43
-23
lines changed

cross-domain/respond-proxy.html

+38-22
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,41 @@
88
<body>
99
<script>
1010
(function () {
11-
var domain, css, url, match, file, ajax, xmlHttp;
12-
11+
var domain, css, query, getQueryString, ajax, xmlHttp;
12+
13+
/*
14+
http://stackoverflow.com/questions/4963673/get-url-array-variables-in-javascript-jquery/4963817#4963817
15+
*/
16+
getQueryString = function() {
17+
var ret = {}, parts, i, p;
18+
19+
parts = (document.location.toString().split("?")[1]).split("&");
20+
21+
for (i = 0; i < parts.length; i++) {
22+
23+
p = parts[i].split("=");
24+
// so strings will be correctly parsed:
25+
p[1] = decodeURIComponent(p[1].replace(/\+/g, " "));
26+
27+
if (p[0].search(/\[\]/) >= 0) { // then it"s an array
28+
p[0] = p[0].replace("[]", "");
29+
30+
if (typeof ret[p[0]] != "object") {
31+
ret[p[0]] = [];
32+
}
33+
ret[p[0]].push(p[1]);
34+
} else {
35+
ret[p[0]] = p[1];
36+
}
37+
}
38+
return ret;
39+
};
40+
1341
ajax = function( url, callback ) {
1442
var req = xmlHttp();
1543
if (!req){
1644
return;
17-
}
45+
}
1846
req.open( "GET", url, true );
1947
req.onreadystatechange = function () {
2048
if ( req.readyState != 4 || req.status != 200 && req.status != 304 ){
@@ -27,7 +55,7 @@
2755
}
2856
req.send();
2957
};
30-
58+
3159
//define ajax obj
3260
xmlHttp = (function() {
3361
var xmlhttpmethod = false,
@@ -51,24 +79,12 @@
5179
return xmlhttpmethod;
5280
};
5381
})();
54-
55-
url = window.location.href;
56-
57-
if (url) {
58-
match = (/css\=(.*\.css)$/).exec(url.slice(url.indexOf('?') + 1));
59-
60-
if (match && match[1]) {
61-
css = match[1];
62-
}
63-
64-
match = (/url\=([^&]+)/).exec(url);
65-
66-
if (match && match[1]) {
67-
domain = match[1];
68-
}
69-
}
70-
71-
if (css) {
82+
83+
query = getQueryString();
84+
css = query["css"];
85+
domain = query["url"];
86+
87+
if (css && domain) {
7288
ajax(css, function (response) {
7389
window.name = response;
7490
window.location.href = domain;

cross-domain/respond.proxy.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
urls = [],
88
refNode;
99

10+
function encode(url){
11+
return win.encodeURIComponent(url);
12+
}
13+
1014
function fakejax( url, callback ){
1115

1216
var iframe,
@@ -26,7 +30,7 @@
2630
docElem.insertBefore(iframe, docElem.firstElementChild || docElem.firstChild );
2731
}
2832

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

3135
function checkFrameName() {
3236
var cssText;

0 commit comments

Comments
 (0)