user149318
user149318

Reputation: 23

How to use a <img> tag to send javascript to a page

I have a tracking pixel img like this one:

<img ... width=1 height=1 src="http://trk.dom123.com/file.aspx?type=1&cp=1" />

I would like to be able to return a javascript from this src. This will then use me to make the analysis I am required to do.

Meaning calling the IMG src will result with a script I generate in my server, injected to the page that fired the pixel (the IMG tga).

Is it possible? if not please suggest any other alternatives.

Many thanks.

Upvotes: 0

Views: 573

Answers (3)

Shadow Wizard
Shadow Wizard

Reputation: 66388

Not possible, alternative would be:

<script type="text/javascript" src="http://trk.dom123.com/file.aspx?type=1&cp=1"></script>

Upvotes: 0

gilly3
gilly3

Reputation: 91497

No, an img tag will not process javascript. It will result in a broken image. The obvious answer is to simply do:

<script type="text/javascript" src="http://trk.dom123.com/file.aspx?type=1&cp=1"></script>

Upvotes: 1

stefan
stefan

Reputation: 2886

It's not possible with modern browsers due to XSS attacks. You will have to include any javascript with a <script> tag

See http://ha.ckers.org/xss.html

Upvotes: 2

Related Questions