Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>oImg.setAttribute('width', '1px'); </code></pre> <p><code>px</code> is for CSS only. Use either:</p> <pre><code>oImg.width = '1'; </code></pre> <p>to set a width through HTML, or:</p> <pre><code>oImg.style.width = '1px'; </code></pre> <p>to set it through CSS.</p> <p>Note that old versions of IE don't create a proper image with <code>document.createElement()</code>, and old versions of KHTML don't create a proper DOM Node with <code>new Image()</code>, so if you want to be fully backwards compatible use something like:</p> <pre><code>// IEWIN boolean previously sniffed through eg. conditional comments function img_create(src, alt, title) { var img = IEWIN ? new Image() : document.createElement('img'); img.src = src; if ( alt != null ) img.alt = alt; if ( title != null ) img.title = title; return img; } </code></pre> <p>Also be slightly wary of <code>document.body.appendChild</code> if the script may execute as the page is in the middle of loading. You can end up with the image in an unexpected place, or a weird JavaScript error on IE. If you need to be able to add it at load-time (but after the <code>&lt;body&gt;</code> element has started), you could try inserting it at the start of the body using <code>body.insertBefore(body.firstChild)</code>.</p> <p>To do this invisibly but still have the image actually load in all browsers, you could insert an absolutely-positioned-off-the-page <code>&lt;div&gt;</code> as the body's first child and put any tracking/preload images you don't want to be visible in there.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload