Example code of JavaScript random link (random hyperlink) and JavaScipt random image

Javascript-icoThe main objective use of random systems is to provide a varied choice. By randomizing the post items, then our blog will feel alive.

Nowadays, so many websites that offer random posts widget, but due to special reasons, then I decided do not use it. Below is an example of JavaScript code that can randomize the link and code to randomize images. Here is example code of JavaScript random link.

JavaScript randomize link / hyperlink:
<script language="JavaScript">
var ambarhalim=new Array()
ambarhalim[0]="http://ambarhalim.blogspot.com/2013/04/tips-and-trick-to-make-website-faster.html,Tips and trick to make website faster"
ambarhalim[1]="http://ambarhalim.blogspot.com/2013/04/modifiers-task-manager-list.html,Modifiers task manager list"
ambarhalim[2]="http://ambarhalim.blogspot.com/2013/04/how-to-fix-optical-mouse.html,How to fix optical mouse"
len=ambarhalim.length // how many entries in the array
rnd=Math.round(Math.random()*(len))
ranlnk=ambarhalim[rnd].split(",") // separate the address and name
document.write("<a href='"+ranlnk[0]+"' title='"+ranlnk[1]+"'>"+ranlnk[1]+"</a>")
document.close()
</script>


JavaScript randomize images:
<script language="JavaScript">
function random_img(){
var img=new Array()
//specify random images below. You can have as many as you wish
img[1]="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNVdg4wCKveA4dFQ4IUxvUOh1LoAfkfk3Ou1RGsrUi0lpZKR1iRcv0TxPD4lZLDTGNN4OErISW5n-eUb9XfAiyfEwdom9PxMRT97O9_NO-hA78sMhx_pk1lnEXHdLrJHBhE7yi1rfnYZHS/s1600/banner2.gif"
img[2]="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9HLLYYi959yCFOtMnEW_YClabXVMrxFrEwN03BT14izKHm-aGrYjgTpwARfzmTiznrYRkfubudUcsdMa64PxqLHXCFfkwnlLSvRnZKrRQau-2sMWmJKvvQiYKl2KjAEhmzwRg-xWetEES/s1600/banner1.gif"
img[3]="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnD0CcGavrbL6YV0yod_U3CnFKVqyQlyxdVKdOeACBFuj0bbpPotUvrvH0_dcvBFN4Ej7aREb71XCj5hArdfEncL7BD4INzcWRj7H0GAiTRY3sieT-EEr0F2p4XhxJo45cNSyaKJTAUVlo/s1600/banner4.gif"
img[4]="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2t5QgZdqbd-Nh-kRCg0GQiuT6BPu4CZJZqBAhvN7oS-FL8r_A6MfHYwopI_UAkRvHwSVfUGymYdHVjflAQNeqLR77rNCl03h7sGi-wZ408uvDzpFjfKaNG8qtf1zMk5kjTuMmbXg1QIYg/s1600/banner3.gif"
img[5]="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxtpKN_zVPXHoyeUaC-85uOjrYs_GcTmebx0w5e8az0L2zVYTyoQSm0aEh8EqUzr00nEdbuo0AFLY3J8zSZtVjlYzOiqr7tV59mIKghv_3rIBconq_wl4q74FTw49Wi-0JrbpQlK8UPLLu/s1600/banner5.gif"
img[6]="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCz5bFRrUFxb7DprRBi3uyW_S5tgnWboHSsgAESXUgQ9V8ycYJCAC3LuCwlRv6wONqxbEdlDhjKi5vgwgcH-WGHGuw5wukZPPW8cxuQ566Dllkfj-QTGvSq32Q4_1wI4hAYlDcO2Iry2QX/s1600/banner6.gif"
var ry=Math.floor(Math.random()*img.length)
if (ry==0)
ry=1
document.write('<img src="'+img[ry]+'" border=0>')
}
random_img()
</script>


Hopefully this script can help you, and make you more excited again.



Keyword: Hyperlink Random Script | Link Random Script | Text Random Script | JavaScript Hyperlink Random Script | Images Random Script | JavaScript Images Random Script

You may also like: