respond-proxy.html 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <!-- Respond.js: min/max-width media query polyfill. Remote proxy (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs -->
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <meta charset="utf-8" />
  6. <title>Respond JS Proxy</title>
  7. </head>
  8. <body>
  9. <script>
  10. (function () {
  11. var domain, css, query, getQueryString, ajax, xmlHttp;
  12. /*
  13. http://stackoverflow.com/questions/4963673/get-url-array-variables-in-javascript-jquery/4963817#4963817
  14. */
  15. getQueryString = function() {
  16. var ret = {}, parts, i, p;
  17. parts = (document.location.toString().split("?")[1]).split("&");
  18. for (i = 0; i < parts.length; i++) {
  19. p = parts[i].split("=");
  20. // so strings will be correctly parsed:
  21. p[1] = decodeURIComponent(p[1].replace(/\+/g, " "));
  22. if (p[0].search(/\[\]/) >= 0) { // then it"s an array
  23. p[0] = p[0].replace("[]", "");
  24. if (typeof ret[p[0]] != "object") {
  25. ret[p[0]] = [];
  26. }
  27. ret[p[0]].push(p[1]);
  28. } else {
  29. ret[p[0]] = p[1];
  30. }
  31. }
  32. return ret;
  33. };
  34. ajax = function( url, callback ) {
  35. var req = xmlHttp();
  36. if (!req){
  37. return;
  38. }
  39. req.open( "GET", url, true );
  40. req.onreadystatechange = function () {
  41. if ( req.readyState != 4 || req.status != 200 && req.status != 304 ){
  42. return;
  43. }
  44. callback( req.responseText );
  45. };
  46. if ( req.readyState == 4 ){
  47. return;
  48. }
  49. req.send();
  50. };
  51. //define ajax obj
  52. xmlHttp = (function() {
  53. var xmlhttpmethod = false,
  54. attempts = [
  55. function(){ return new XMLHttpRequest(); },
  56. function(){ return new ActiveXObject("Microsoft.XMLHTTP"); },
  57. function(){ return new ActiveXObject("MSXML2.XMLHTTP.3.0"); }
  58. ],
  59. al = attempts.length;
  60. while( al-- ){
  61. try {
  62. xmlhttpmethod = attempts[ al ]();
  63. }
  64. catch(e) {
  65. continue;
  66. }
  67. break;
  68. }
  69. return function(){
  70. return xmlhttpmethod;
  71. };
  72. })();
  73. query = getQueryString();
  74. css = query["css"];
  75. domain = query["url"];
  76. if (css && domain) {
  77. ajax(css, function (response) {
  78. window.name = response;
  79. window.location.href = domain;
  80. });
  81. }
  82. }());
  83. </script>
  84. </body>
  85. </html>