开发者

Firefox: window.open prevents img.src from loading

开发者 https://www.devze.com 2023-01-02 11:47 出处:网络
I\'ve heard some rumors I can\'t seem te replicate. And now I\'m curious if any ofyou have experiences with this issue.

I've heard some rumors I can't seem te replicate. And now I'm curious if any of you have experiences with this issue.

Our analytics system uses JavaScript to generate an image of 1x1 pixels. This 'image' is registering all of our visitors behaviour.

Now consider the following (simplified) JavaScript code:

function visitLink (url)
{
  var randomNumber = Math.random();

  var img = new Image();
  img.src = 'http://www.example.com/log?url=' + escape(url) + '&' + randomNumber;

  window.open(link.href);

  return false;
}

Rumor says; window.open can block the background loading of img.src in some versions of FireFox.

It's working in my version of开发者_运维百科 FireFox though. Am I seeing ghosts here? If not; any idea how to replicate the issue?

Erik


In my understanding JavaScript is a singlethreaded language and interprets from top to bottom of your function.

Therefore if something should be blocked, its the opening of the window and not the loading of the image. A quick repro of mine indeed shows this behaviour.

function visitLink (url)
    {
      var img = new Image();
      img.src = 'http://www.meshfields.com/' + url;

      document.getElementById("myImgId").src = img.src;      
      window.open("http://www.meshfields.com/index.html");
    }

Markup:

 <a href="javascript:visitLink('myBigPicture.jpg');">Link</a>

 <img id="myId" src="" />

All the browsers show no problems with loading of the pic. Tested on Safari, Chrome, Firefox, Opera on MacOSX. However I apparently did not use your inhouse analytics system to generate my pic.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号