# Java script hyperlink code



## Ross (May 9, 2002)

OK so we want the image addy below to be clickable as a hyper link to 
http://ruthsfiberphotos.blogspot.com/ 

Help!!  TIA!!


var HeadImage = '';
var FootImage = 'http://feltingandfiberstudio.files.wordpress.com/2012/02/ruth-banner-ad-one-730-x-92.jpg'; 
var first = document.body.getElementsByTagName('table')[0];
var fifth = document.body.getElementsByTagName('br')[4]
var image1 = document.createElement('img');
var image2 = document.createElement('img');
var center1 = document.createElement('center');
var center2 = document.createElement('center');
image1.border = 0;
image1.src = HeadImage;
image2.border = 0;
image2.src = FootImage
center1.appendChild( image1 );
center2.appendChild( image2 );
document.body.insertBefore( center1, first );
document.body.insertBefore( center2, fifth );
</script>


----------



## How Do I (Feb 11, 2008)

Any specific reason you want to use javascript to link?

This would be a simple HTML image link.

```
<a href="http://ruthsfiberphotos.blogspot.com/"><img src="http://feltingandfiberstudio.files.wordpress.com/2012/02/ruth-banner-ad-one-730-x-92.jpg"></a>
```
ETA - No help on the javascript link. Best I could tell, that javascript code above is for placing images in some sort of welcome header/footer table. But I don't know enough about javascript to say for sure though.


----------



## Ross (May 9, 2002)

Yeah I'm no java expert either. Here;s what i have so far and it doesn't work
<br>
<script type='text/javascript'>
var HeadImage = '';
var FootImage = 'http://feltingandfiberstudio.files.wordpress.com/2012/02/ruth-banner-ad-one-730-x-92.jpg'; 
var first = document.body.getElementsByTagName('table')[0];
var fifth = document.body.getElementsByTagName('br')[4]
var image1 = document.createElement('img');
var image2 = document.createElement('img');
var center1 = document.createElement('center');
var center2 = document.createElement('center');
var link = document.createElement('a');

image1.border = 0;
image1.src = HeadImage;
image2.border = 0;
image2.src = FootImage;
link.href = 'http://ruthsfiberphotos.blogspot.com ';
center1.appendChild( image1 );
center2.appendChild( image2 );
link.appendChild(image2 );
document.body.insertBefore( center1, first );
document.body.insertBefore( center2, fifth );

</script>


----------



## How Do I (Feb 11, 2008)

Do you have an example of where this script is working? A demo, if you will? I tried to load it on my website and all I get is a broken image. Seems several people on Proboards having the same problem with this script.

I believe I found a demo of it,


```
http://quilfordskin1.proboards.com/
```
but it doesn't even work over there. If you know of a site where it _is_ working, should be able to figure how they got it to work.


----------



## Ross (May 9, 2002)

When my wife asked me I said sure easy and I cranked out the same HTML you did, then she showed me where the admin on her felting forum was havign trouble so it seemed easy enough to find the code to drop into java script to make the picture clickable. It seems as if it would be easier to make a button into a picture that is then clickable. it would be even easier to add a button under the picture at this point, but it seems silly its so difficult to do this in java when its so easy in html. Thanks for your ideas I'm going to keep plugging away at it for a bit.


----------



## Ross (May 9, 2002)

Ah to heck with it I blanked out the image in the Java left it for dead and plugged in the html link adding <center> to the string and it works fine. Nothing to be gained using the Java that was there except a learning experience! Thanks anyhow!


----------

