diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index 8d63340d1e..3a3ef27493 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -1346,7 +1346,21 @@ OpenLayers.Util.isEquivalentUrl = function(url1, url2, options) { OpenLayers.Util.createUrlObject = function(url, options) { options = options || {}; - var urlObject = {}; + // deal with relative urls first + if(!(/^\w+:\/\//).test(url)) { + var loc = window.location; + var port = loc.port ? ":" + loc.port : ""; + var fullUrl = loc.protocol + "//" + loc.host + port; + if(url.indexOf("/") === 0) { + // full pathname + url = fullUrl + url; + } else { + // relative to current path + var parts = loc.pathname.split("/"); + parts.pop(); + url = fullUrl + parts.join("/") + "/" + url; + } + } if (options.ignoreCase) { url = url.toLowerCase(); @@ -1355,13 +1369,15 @@ OpenLayers.Util.createUrlObject = function(url, options) { var a = document.createElement('a'); a.href = url; + var urlObject = {}; + //host (without port) // if we don't have a host (which is the case with URLs starting with "/" // in IE), take the window location's host to match other browsers that // fill in the window's location host automatically urlObject.host = a.host || window.location.host; var port = a.port; - if (port.length <= 0) { + if (port.length > 0) { var newHostLength = urlObject.host.length - (port.length); urlObject.host = urlObject.host.substring(0, newHostLength); }