Stand Coder Stand Coder - 7 days ago 7
Javascript Question

How to send http request on img tag's onerror attribute?

I've tried as follows, but it doesn't work

<body>
<img src=a onerror="document.write('<img src=\"http://www.somdomain.com:8088/alert?type=teSt&msg=www\">')">
</body>

Answer

\ is not an escape character in HTML.

To put a " character inside an attribute value delimited with " characters, you must represent it as an entity. e.g. &quot;.


Keep in mind that cross-origin restrictions prevent load and error events firing on images srced from a different origin.

Comments