Skip to content

Commit

Permalink
Resolves issue #100: CDN/x-domain setup fails in IE7 and IE6 when <ba…
Browse files Browse the repository at this point in the history
…se> tag is used

- Suppresses a false-positive when a <base> element exists but no link protocol is found.
- The x-domain script now correctly tests for the existence of a <base> element and proxies/redirects using that reference.
  • Loading branch information
doctyper committed Feb 1, 2012
1 parent c82ab67 commit 0764de5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
18 changes: 14 additions & 4 deletions cross-domain/respond.proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var docElem = doc.documentElement,
proxyURL = doc.getElementById("respond-proxy").href,
redirectURL = (doc.getElementById("respond-redirect") || location).href,
baseElem = doc.getElementsByTagName("base")[0],
urls = [],
refNode;

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

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

function checkFrameName() {
var cssText;
Expand Down Expand Up @@ -60,14 +61,22 @@

win.setTimeout(checkFrameName, 500);
}

function checkBaseURL(href) {
if (baseElem && href.indexOf(baseElem.href) === -1) {
bref = (/\/$/).test(baseElem.href) ? baseElem.href : (baseElem.href + "/");
href = bref + href;
}

return href;
}

function checkRedirectURL() {
// IE6 & IE7 don't build out absolute urls in <link /> attributes.
// So respond.proxy.gif remains relative instead of http://example.com/respond.proxy.gif.
// This trickery resolves that issue.
if (~ !redirectURL.indexOf(location.host)) {

// Inject an <a> attribute, with the redirectURL
var fakeLink = doc.createElement("div");

fakeLink.innerHTML = '<a href="' + redirectURL + '"></a>';
Expand All @@ -89,10 +98,11 @@

var thislink = links[i],
href = links[i].href,
ext = /^([a-zA-Z]+?:(\/\/)?(www\.)?)/;
extreg = (/^([a-zA-Z]+?:(\/\/)?(www\.)?)/).test( href ),
ext = (baseElem && !extreg) || extreg;

//make sure it's an external stylesheet
if( thislink.rel.indexOf( "stylesheet" ) >= 0 && ext.test( href ) ){
if( thislink.rel.indexOf( "stylesheet" ) >= 0 && ext ){
(function( link ){
fakejax( href, function( css ){
link.styleSheet.rawCssText = css;
Expand Down
3 changes: 2 additions & 1 deletion respond.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ window.matchMedia = window.matchMedia || (function(doc, undefined){
parsedSheets = {},
resizeThrottle = 30,
head = doc.getElementsByTagName( "head" )[0] || docElem,
base = doc.getElementsByTagName( "base" )[0],
links = head.getElementsByTagName( "link" ),
requestQueue = [],

Expand All @@ -76,7 +77,7 @@ window.matchMedia = window.matchMedia || (function(doc, undefined){
translate( sheet.styleSheet.rawCssText, href, media );
parsedSheets[ href ] = true;
} else {
if( !/^([a-zA-Z:]*\/\/)/.test( href )
if( (!base && !/^([a-zA-Z:]*\/\/)/.test( href ))
|| href.replace( RegExp.$1, "" ).split( "/" )[0] === win.location.host ){
requestQueue.push( {
href: href,
Expand Down

0 comments on commit 0764de5

Please sign in to comment.