• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Javacript onclick image to go to a website

  • Thread starter Thread starter Q
  • Start date Start date

Q

Lifer
I am making a simple website that consists of a lot of images, so I am using Mozilla's WYSIWYG editor in SeaMonkey.

Anyway, after putting in a lot of links in the images, it ends up changing the dimensions of the page so there is about 500px of empty space on the bottom. This is due to the anchor tags.

Now, I'd like to just have a javascript that I can put in the image properties to goto the site, instead of adding Anchor tags.

So, if I have an image, what is the code (onclick) to make it goto a website?
 
<img src="whatever.jpg" height="200" width= "200" onclick="javascript:location.href='blah.html';"/>

^ like joshg said.

It does work. But I'm guessing there is something else going on here. Can you paste your code?
 
Originally posted by: joshsquall
<div class="FTQUOTE"><begin quote>Originally posted by: Quintox
It works, the little finger just doesn't show up.. 🙂</end quote></div>

Add style="cursor: pointer; cursor: hand;" to the anchor tag.

or better, add a dummy link

<a href="#"><img src="whatever.jpg" height="200" width= "200" onclick="javascript:location.href='blah.html';"/>,</a>

this way the cursor will change to a hand but if you click it without the javascript nothing will happen

btw it's good practice to pair onclick() events with onkeypress() in case the user is using his keyboard! 🙂
 
Also I was going to mention the other day... Honestly if you are just doing a location.href and no other functionality, not opening a popup, or anuthing like that...... what's the point? The anchor tag would get you the exact same thing. And I can promise that just by having an anchor tag isn't adding 500px to your page! 🙂
 
Back
Top