...

View Full Version : Worlds most simple script? But I cant do it. Help!



cromagx
11-16-2010, 12:49 PM
Hi all,

I know this sounds absurd, but I like to display a clickable image in javascript. I have searched the net for like 2 hours, and I simply CANT find any page that can help me with that extremely simple javascript.

This is how its look like in html:


<a href="http://www.horse.com"><img src="jul.jpg" width="468" height="80" border="0" /></a>

Please! How can I make that simple code in javascript?! :confused::confused:

Thanks!

Philip M
11-16-2010, 12:53 PM
There is nothing wrong with your code, and when I test it (with an image of my own) I get www.horse.com.

So what do you think is wrong?


All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

abduraooft
11-16-2010, 01:10 PM
but I like to display a clickable image in javascript Like

document.write('<a href="http://www.horse.com"><img src="jul.jpg" width="468" height="80" border="0" /></a>');

cromagx
11-16-2010, 02:52 PM
Thanks abduraooft!!

That was all I needed!

Philip M
11-16-2010, 04:01 PM
Ah, I wondered about that but rejected it because it seemed (a) too obvious and (b) pointless.

document.write statements must be run before the page finishes loading. Any document.write statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page. So document.write is at best really only useful to write the original content of your page. It cannot be used to update the content of your page after that page has loaded.

Example for crmagx showing this effect:-


ABCDEF<br>
<a href="http://www.horse.com"><img src="One.jpg" width="468" height="80" border="0" /></a>
<br>
<input type = "button" value = "Display Clickable Image" onclick = "writeit()">
<script type = "text/javascript">
function writeit() {
document.write('<a href="http://www.horse.com"><img src="One.jpg" width="468" height="80" border="0" /></a>');
}
</script>

So if crmagx wants to display the image once the page has loaded he should use a styled <div> "display: hidden" > "display:block".



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum