Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> var body = document.getElementsByTagName("body")[0];

You can just use document.body.

I also suggest to use a data URL instead. E.g. "data:," is an empty plain text file, which, as you can imagine, won't be interpreted as a valid image.

  let image = new Image();
  image.onerror = () => {
    console.log(image.width); // 0 -> headless
  };
  document.body.appendChild(image);
  image.src = 'data:,';
> In case of a vanilla Chrome, the image has a width and height that depends on the zoom of the browser

The zoom doesn't affect this. It's always in CSS "pixels".



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: