Help needed in Javascript + Image + HREF

In the above code, I am adding the javascript onclick method to the image tag. When I click the image once, and I click back, it should return to the page from which it came. Instead, he stayed on one page. Is there any way to avoid this? (maybe instead of href="#" ) install something else. The reason I set href="#" is to make my cursor turn into a hand, except that it is useless.

This happens in Firefox. In IE, it works great.

Please, help. Thank.

+1
javascript html css
Mar 12
source share
5 answers
 <a href="#"><img src="http://www.google.com/intl/en_ALL/images/logo.gif" onClick="alert('hi'); return false;"/></a> 

you need to add return false; into your onclick events if you don’t want to download the link.

+1
Mar 12
source share

I set href = "#" to make my cursor turn into a hand, except that it is useless.

You can remove the <a href="#"> and add the cursor: pointer style to the image:

<img src="logo.gif" style="cursor: pointer;" />

... to turn the cursor into a hand.

On the other hand, it is probably best to follow the recommendations for progressive improvement, as David suggested in a different answer .

+4
Mar 12
source share
 <a href="#"> <img src="http://www.google.com/intl/en_ALL/images/logo.gif" onClick="alert('hi'); return false;"/> </a> 

return false prevents the default action from occurring (in this case, switching to "#"), and then navigating back will return you to the previous page, and not to the current page without "#".

+1
Mar 12
source share

Follow pragmatic recommendations for progressive improvement . In particular: Work on the work.

+1
Mar 12
source share

Use this instead: <img src = "http://www.google.com/intl/en_ALL/images/logo.gif" onClick = "alert ('hi')" style = "cursor: pointer" />

+1
Mar 12 '10 at 14:05
source share



All Articles