Reputation: 1421
I would like to know, how i can show a image through my javascript code.
Example:
javascript.php:
echo '<script type="text/javascript" src="http://domain.com/show_image.php"></script>';
show_image.php:
echo '<img src="http://domain.com/image/show_image.png" />';
This will not show anything. Anyone know why? :)
Upvotes: 0
Views: 1127
Reputation: 4412
That should be:
echo 'document.write("<img src=\"http://domain.com/image/show_image.png\">")';
above assumes proper content-type for response
header('Content-type: text/javascript', true);
Upvotes: 2
Reputation:
Assuming you want the <img>
to appear where the <script>
is, first change the <script>
to something like this:
<script id="imagePlace" type="text/javascript"
src="http://domain.com/show_image.php"></script>
Then change show_image.php to this:
var scr = document.getElementById('imagePlace');
var img = document.createElement('img');
img.setAttribute("src","http://domain.com/image/show_image.png");
scr.parentNode.insertBefore( img, scr );
Upvotes: 1
Reputation: 490647
Because script
elements are not designed to show images.
Use include 'show_image.php'
.
Upvotes: 1