Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Worlds most simple script? But I cant do it. Help!

    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:

    Code:
    <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?!

    Thanks!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    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.

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    but I like to display a clickable image in javascript
    Like
    Code:
    document.write('<a href="http://www.horse.com"><img src="jul.jpg" width="468" height="80" border="0" /></a>');
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks abduraooft!!

    That was all I needed!

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    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:-

    Code:
    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".
    Last edited by Philip M; 11-16-2010 at 04:11 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •