javascript crossbrowser new Image()
<p>What is wrong with this function? It works in Opera and Firefox, but doens't work on Safari under the Windows</p>

<pre><code>function getImage(url) {        
    var image = document.createElement('img'); // new Image(1, 1); 
    image.src = url;
    image.onload = function() {};
}
</code></pre>

<p>when I try  getImage('<a href="http://site.com/someservlet.gif" rel="nofollow">http://site.com/someservlet.gif</a>')
This image is not loaded (because someservlet.gif logs all requests)
It works in Opera and Firefox, but not in Safari. I tried "new Image()"
and "document.createElement('img')" -- the same result.</p>

<p>========== UPDATE:
Function works well when it's called directly, problem start when it's called from event listener</p>

<pre><code>&lt;a href="http://google.com/" 
onclick="getImage('http://127.0.0.1/pic/img.gif?rnd=' + Math.random());"&gt;google&lt;/a&gt;

&lt;a href="#" 
onclick="getImage('http://127.0.0.1/pic/img.gif?rnd=' + Math.random());"&gt;local&lt;/a&gt;

&lt;script type="text/javascript"&gt;
function getImage(url) {
    var image = document.createElement('img');
    alert('1');
    image.onload = function() {alert(image.src);};
    image.src = url;
    alert('2');
}
&lt;/script&gt;
</code></pre>

<p>"local" link works well in Firefox, Opera and Safari (but Safari shows alert1, alert2 and then alert with "src" for some reason, while other browsers  show alert1, alertSrc, alert2)</p>

<p>"google" link Opera, Firefox - works well (alert1, alertSrc, alert2), but Safari doesn't - show alertSrc. In Safari you see alert1, alert2 and thats all. Servlet "/pic/img.gif" doesn't get request when someone clicks "google" link from Safari. </p>

<p>What is the problem, how to solve it?</p>

<p>Thanks. </p>
