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 9 of 9
  1. #1
    New Coder
    Join Date
    Aug 2008
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    going to home page when no HTML link

    I am new to javascript.

    My objective is to go to the home page when I click on an image (that is not a link). How do I do this?

    I suspect I should give the img tag an onClick='goHome()' attribute and write a goHome() function. However, I do not know the javascript command to direct the browser to the home page.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Code:
    function goHome() {
    window.location = "http://yoursite.com/homepage.html"
    }

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

  • #3
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts
    you can also just make it thru plain html, <a href='myHomepage.htm'><img src='myImage.jpg' /></a>, no need of Javascript here.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Quote Originally Posted by sybil6 View Post
    you can also just make it thru plain html, <a href='myHomepage.htm'><img src='myImage.jpg' /></a>, no need of Javascript here.
    Yes, indeed. But the OP specified:-

    "My objective is to go to the home page when I click on an image (that is not a link)".


    JESUS IS COMING VERY SOON. GET EXCITED!
    Near me is an old persons' home in a road called St Peter's Close.
    Last edited by Philip M; 09-07-2008 at 10:48 AM.

  • #5
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts
    yes right, i didnt get it.

  • #6
    New Coder
    Join Date
    Aug 2008
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks. This seems work too. Is this ok? I prefer not to code in the domain name if possible.

    function goHome() {
    window.location = "/l"
    }

  • #7
    New Coder
    Join Date
    Aug 2008
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sybil6 View Post
    you can also just make it thru plain html, <a href='myHomepage.htm'><img src='myImage.jpg' /></a>, no need of Javascript here.
    Yes, the image link works that way in all cases on my XP system. I didn't test Opera. However, IE and Netscape outline the image in blue if it has not been clicked and purple it it has. Safari and Google browsers didn't outline the image at all which is what I want in this particular case.

    I tried to make the outline box the same color as the background with CSS but I was unable to accomplish that. I do not know why I failed. As a result I decided to not make the image an HTML link and to use a javascript event for the link.

  • #8
    Regular Coder
    Join Date
    May 2008
    Posts
    135
    Thanks
    13
    Thanked 10 Times in 10 Posts
    if you are trying to make the image a link without having any outline around it you can simply do this with CSS.

    <style type="text/css">

    a img { border: none; }

    </style>


    all you need to do is put the image in some anchor tags and then in css specify that any anchor that has an image in it should have no border.

    no need for javascript (if ive understood what you are trying to do correctly! lol)

  • #9
    New Coder
    Join Date
    Aug 2008
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Yep, you are 100% correct! All I can say is that I learned a lot from the exercise which I am sure to apply elsewhere.


  •  

    Posting Permissions

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