Expand partial URL into full (like in image.src)
<p>I'm trying to write an <code>onerror</code> handler for images that replaces them with a loading image and then periodically tries to reload them. The problem I'm having is that if the loading image fails to load, it goes into an infinite loop of failure. I'm trying to deal with this by checking if the URL is the loading image:</p>

<pre><code>if(photo.src != loadingImage) {
    // Try to reload the image
}
</code></pre>

<p>Unfortunately, <code>loadingImage</code> can be a relative URL (<code>/images/loadingImage.jpg</code>), but <code>photo.src</code> is always a full URL (<code>http://example.com/images/loadingImage.jpg</code>). Is there any way to generate this full URL without passing the function any more information? Obviously I could pass it the host name, or require full URLs, but I'd like to keep this function's interface as simple as possible.</p>

<p>EDIT:</p>

<p>Basically what I want is to guarantee that if I do <code>photo.src = loadingImage</code>, that this will be true: <code>photo.src === loadingImage</code>. The constraint is that I know nothing about <code>loadingImage</code> except that it's a valid URL (it could be absolute, relative to the server, or relative to the current page). <code>photo.src</code> can be any (absolute) URL, so not necessarily on the same domain as <code>loadingImage</code>.</p>
