Created
April 12, 2012 14:04
-
-
Save rocktronica/2367523 to your computer and use it in GitHub Desktop.
trying to fix false absolute URLs when using IP address as localhost
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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>'); | |
} | |
} ()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
browserling condition, pathname fix for ie6, and commented addcss