Skip to content

Instantly share code, notes, and snippets.

@rocktronica
Created April 12, 2012 14:04
Show Gist options
  • Save rocktronica/2367523 to your computer and use it in GitHub Desktop.
Save rocktronica/2367523 to your computer and use it in GitHub Desktop.
trying to fix false absolute URLs when using IP address as localhost
(function () {
// only run on IPs and browserling tunnel
if ((!!parseInt(location.host.replace(/\./g, ''), 10)) || (!!location.href.match('browserling'))) {
// fake out DOM to get URL ports
function getPort(sUrl) {
var a = document.createElement("a");
a.href = sUrl;
return a.port;
}
// links
var a = document.getElementsByTagName("a"), aLength = a.length;
for (var iA = 0; iA < aLength; iA++) {
if (!!a[iA].port) { a[iA].href = (a[iA].pathname.charAt(0) === '/' ? '' : '/') + a[iA].pathname; }
}
// images
var img = document.getElementsByTagName("img"), imgLength = img.length;
for (var iImg = 0; iImg < imgLength; iImg++) {
if (!!getPort(img[iImg].src)) { img[iImg].src = "/" + img[iImg].src.split("/").slice(3).join("/"); }
}
// uncomment to init addCSS bookmarklet
// $.getScript("http://rocktronica.github.com/Add-CSS-Bookmarklet/addcss.js"); $("head").append('<style type="text/css">.ie6 #txtAddCss{background:#000 !important;position:absolute;bottom:5%;right:5%}.ie6 #spAddCssHandle{display:none}</style>');
}
} ());
@rocktronica
Copy link
Author

browserling condition, pathname fix for ie6, and commented addcss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment