Skip to content

Commit

Permalink
Respond.js proxy. The iframe URL is constructed as follows:
Browse files Browse the repository at this point in the history
http://cdnexample.com/respond-proxy.html?url=http://originalurl.com/x-domain-end-point.html&css=http://cdnexample.com/example.css

The URL is parsed, CSS file is extracted and stored in window.name. The file then redirects to the correct URL for MQ parsing.
  • Loading branch information
doctyper committed Jun 3, 2011
1 parent eca97d8 commit e7a2a59
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions test/proxy/respond-proxy.html
@@ -0,0 +1,80 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Respond JS Proxy</title>
</head>
<body>
<script>
(function () {
var domain, css, url, match, file, ajax, xmlHttp;

ajax = function( url, callback ) {
var req = xmlHttp();
if (!req){
return;
}
req.open( "GET", url, true );
req.onreadystatechange = function () {
if ( req.readyState != 4 || req.status != 200 && req.status != 304 ){
return;
}
callback( req.responseText );
}
if ( req.readyState == 4 ){
return;
}
req.send();
};

//define ajax obj
xmlHttp = (function() {
var xmlhttpmethod = false,
attempts = [
function(){ return new ActiveXObject("Microsoft.XMLHTTP") },
function(){ return new XMLHttpRequest() }
],
al = attempts.length;

while( al-- ){
try {
xmlhttpmethod = attempts[ al ]();
}
catch(e) {
continue;
}
break;
}
return function(){
return xmlhttpmethod;
};
})();

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];
}
}

if (css) {
ajax(css, function (response) {
var encodedText = window.encodeURIComponent(response);

window.name = encodedText;
window.location.href = domain;
});
}
}());
</script>
</body>
</html>

0 comments on commit e7a2a59

Please sign in to comment.