Jump to content

Which is the proper JS hotlinking code?


Videogamer555

Recommended Posts

All 4 of the below pieces of code have the same linking affect, with no differences that I can see (I'm using the latest version of Firefox as my browser), but one of them must be the "correct" technique.

<img src="mypic.jpg" onclick="document.location='http://www.google.com'" />

<img src="mypic.jpg" onclick="window.location='http://www.google.com'" />

<img src="mypic.jpg" onclick="self.location='http://www.google.com'" />

<img src="mypic.jpg" onclick="location='http://www.google.com'" />

Which one is the official correct techniuqe for using JS for turning a part of a web page (such as an image) into a link?

Link to comment
Share on other sites

The best idea would be to wrap the <img> tag in an anchor:

<a href="http://www.google.com/"><img></a>

In Javascript, document.location doesn't exist, window.location and location are the same thing, self.location has to do with frames which you shouldn't need to worry about.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...