What is wrong with this function? It works in Opera and Firefox, but doens't work on Safari under the Windows
function getImage(url) {
var image = document.createElement('img'); // new Image(1, 1);
image.src = url;
image.onload = function() {};
}
when I try getImage('http://site.com/someservlet.gif') 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.
========== UPDATE: Function works well when it's called directly, problem start when it's called from event listener
<a href="http://google.com/"
onclick="getImage('http://127.0.0.1/pic/img.gif?rnd=' + Math.random());">google</a>
<a href="#"
onclick="getImage('http://127.0.0.1/pic/img.gif?rnd=' + Math.random());">local</a>
<script type="text/javascript">
function getImage(url) {
var image = document.createElement('img');
alert('1');
image.onload = function() {alert(image.src);};
image.src = url;
alert('2');
}
</script>
"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)
"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.
What is the problem, how to solve it?
Thanks.