...

View Full Version : going to home page when no HTML link



dave-
09-07-2008, 10:09 AM
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.

Philip M
09-07-2008, 10:47 AM
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.

sybil6
09-07-2008, 11:17 AM
you can also just make it thru plain html, <a href='myHomepage.htm'><img src='myImage.jpg' /></a>, no need of Javascript here.

Philip M
09-07-2008, 11:45 AM
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.

sybil6
09-07-2008, 11:52 AM
yes right, i didnt get it.

dave-
09-07-2008, 01:39 PM
Thanks. This seems work too. Is this ok? I prefer not to code in the domain name if possible.

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

dave-
09-07-2008, 01:58 PM
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.

mike182uk
09-07-2008, 03:30 PM
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)

dave-
09-08-2008, 07:22 PM
Yep, you are 100% correct! :o All I can say is that I learned a lot from the exercise which I am sure to apply elsewhere. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum