Thursday, July 28, 2011

Random image on refresh using javascript, Change image on every refresh, Another Picture, every refresh

Changing things on every refresh to your website is attractive feature to retain your visitors to your website.

Because it create suspense into visitor about the next information.

So I want to share this JavaScript.

JavaScript Code
var ranNum = Math.floor(Math.random() * 3);
        //alert(ranNum);
        var quote = new Array(3)
        var lnk = new Array(3)


          quote[0] = "home/modeltiranga.jpg";
          quote[1] = "home/modelbeauty.jpg";        
          quote[2] = "home/modeltiranga.jpg";


          lnk[0] = "product_category.aspx?id=446";      

          lnk[1] = "Product_category.aspx?samemodel=17440"; 
          lnk[2] = "product_category.aspx?id=446"; 

Put this code into HEAD tag.


HTML Code
<script type="text/javascript">                                
 //<![CDATA[
                                    document.write('<a href="' + lnk[ranNum] + '"><img src="' + quote[ranNum] + '" alt="Mart of Images"/></a>')
 //]]>
</script>

put this code into BODY tags



No comments: