Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I need to create a php script that renders an image... no problem.

However, what i'd like to do is have the image rendering script trigger some javascript code whenever the script is started up.

Is it possible to include javascript code within the image generating php script without it screwing up the image?

share|improve this question
1  
No. Javascript runs on the client, and images cannot contain Javascript. –  SLaks Sep 9 '13 at 21:19
add comment

1 Answer

up vote 2 down vote accepted

Even if you add some javascript code into the image the browser will not run it.

share|improve this answer
    
Is there a way to send a request to a second page when the image is called? –  Brds Sep 9 '13 at 21:20
    
You can attach onload handler to the image tag to see when the image is loaded. –  Krasimir Sep 9 '13 at 21:22
    
The image being generated will be going into an email... So i can't put an onload to the img tag :( –  Brds Sep 9 '13 at 21:23
    
@Brds: You can't run JS in emails, period. –  SLaks Sep 9 '13 at 21:24
    
Right, I was trying to run JS in the script that generates the image used in the email, not in the email itself. I'm wondering if maybe a header() call in the script might do the job. –  Brds Sep 9 '13 at 21:26
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.