JSCboulder
Technical User
Here is the question:
the script below is simply taking a random image from a list and writing in on the page.
How do I divide this up so I don't have to put the whole script on the html page? In other words what can be put into a js file and imported, and how would the snippet look that actually sits in the html, calls that script and writes the image?
thanks,
JSC Boulder
<script type="text/javascript">
<!--
function random_imglink(){
var myimages=new Array()
myimages[1]="<?=_p()?>/images/groups/img1.jpg"
myimages[2]="<?=_p()?>/images/groups/img2.jpg"
myimages[3]="<?=_p()?>/images/groups/img3.jpg"
myimages[4]="<?=_p()?>/images/groups/img4.jpg"
myimages[5]="<?=_p()?>/images/groups/img5.jpg"
var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<a href= src="'+myimages[ry]+'" border=0 alt=groups></a>')
}
random_imglink()
//-->
</script>
the script below is simply taking a random image from a list and writing in on the page.
How do I divide this up so I don't have to put the whole script on the html page? In other words what can be put into a js file and imported, and how would the snippet look that actually sits in the html, calls that script and writes the image?
thanks,
JSC Boulder
<script type="text/javascript">
<!--
function random_imglink(){
var myimages=new Array()
myimages[1]="<?=_p()?>/images/groups/img1.jpg"
myimages[2]="<?=_p()?>/images/groups/img2.jpg"
myimages[3]="<?=_p()?>/images/groups/img3.jpg"
myimages[4]="<?=_p()?>/images/groups/img4.jpg"
myimages[5]="<?=_p()?>/images/groups/img5.jpg"
var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<a href= src="'+myimages[ry]+'" border=0 alt=groups></a>')
}
random_imglink()
//-->
</script>