Implement some random events with JavaScript

Source: Internet
Author: User
Tags date array getcolor goto implement
javascript| Random 1, random ads

<script language= "JavaScript" >
<!--Begin
var how_many_ads = 3;
var now = new Date ()
var sec = Now.getseconds ()
var ad = sec% How_many_ads;
Ad +=1;
if (ad==1) {
Txt= "The world ' s largest Online bookstore, Amazon.com";
Url= "http://www.amazon.com";
alt= "Amazon.com";
Banner= "Ad12669st1sz1sq1_ban1.gif";
Width= "468";
height= "60";
}
if (ad==2) {
Txt= "Palm III by 3Com, in stock!";
Url= "http://cybershop.com/";
alt= "cybershop.com";
Banner= "Ad13189st1sz1sq5_ban10.gif";
Width= "468";
height= "60";
}
if (ad==3) {
Txt= "Find it at goto.com";
Url= "http://www.goto.com";
alt= "GoTo.com";
Banner= "Ad13700st1sz1sq1_ban1.gif";
Width= "468";
height= "60";
}
document.write (' <center> ');
document.write (' <a href=\ ' + url + ' \ ' target=\ ' _top\ ' > ');
document.write (' document.write (width + ' height= ' + height + ');
document.write (' alt=\ ' + ALT + ' \ "border=0>
');
document.write (' <small> ' + txt + ' </small></a> ');
document.write (' </center> ');
End-->
</SCRIPT>
2. Random background color

<HTML>
<HEAD>
<title>random background</title>

<script language= "JavaScript" >
<!--
function BackColor (form) {
temp = ""
for (var i = 0; i < i++) {
temp = Form.color[i].value
if (form.color[i].checked) {Document.bgcolor = temp}
}
}
function Randombackground () {
Document.bgcolor = GetColor ()
}
function GetColor () {
currentdate = new Date ()
BackgroundColor = Currentdate.getseconds ()
if (BackgroundColor > 44)
BackgroundColor = backgroundcolor-45
else if (BackgroundColor > 29)
BackgroundColor = backgroundcolor-30
else if (BackgroundColor > 15)
BackgroundColor = backgroundcolor-16
if (backgroundcolor = 0)
return "Olive";
else if (backgroundcolor = 1)
return "Teal";
else if (BackgroundColor = 2)
return "Red";
else if (BackgroundColor = 3)
Return "Blue";
else if (BackgroundColor = 4)
return "Maroon";
else if (BackgroundColor = 5)
Return "Navy";
else if (BackgroundColor = 6)
return "lime";
else if (BackgroundColor = 7)
return "Fuschia";
else if (BackgroundColor = 8)
return "green";
else if (BackgroundColor = 9)
return "Purple";
else if (BackgroundColor = 10)
Return "Gray";
else if (backgroundcolor = 11)
return "Yellow";
else if (BackgroundColor = 12)
Return "Aqua";
else if (backgroundcolor = 13)
Return to "BLACK";
else if (backgroundcolor = 14)
Return to "white";
else if (backgroundcolor = 15)
return "Silver";
}
End-->
</SCRIPT>
</HEAD>

<body bgcolor= #ffffff vlink= #0000ff >

<CENTER>
<FORM>
<input type= "button" value= "Random background color" >
</FORM>
</CENTER>

</body>
3. Random background pattern

<HTML>
<HEAD>
<title>random images</title>

<script language= "JavaScript" >

Today=new Date ();
Jran=today.gettime ();
var number = 3;
var random_number= "";
var image= "";
var text_color= "";

ia=9301;
ic=49297;
im=233280;
Jran = (jran*ia+ic)% im;
Random_number = Math.ceil ((jran/(im*1.0)) *number);

if (random_number==1) {
Text_color= "000000";
Image= "Bg1.gif";
}
if (random_number==2) {
Text_color= "000000";
Image= "Bg2.jpg";
}
if (random_number==3) {
Text_color= "000000";
Image= "Bg3.gif";
}
End-->
</SCRIPT>
</HEAD>

<script language= "JavaScript" >
<!--Begin
Document.open ();
document.write ("<body background= '" +image+ "' text= '" +text_color+ "' vlink= #0000ff >");
document.write ("<CENTER></CENTER>");
End-->
</SCRIPT>

<FORM>
<input type= "button" value= "Reload Page" >
</FORM>
<script language= "JavaScript" >
<!--Begin
document.write ("<center><font size=-1 color=red>background Image: (" +image+ ") </font></center > ");
End-->
</SCRIPT>

</body>4. Random pattern

Place the following code between <script language= "JavaScript" >
A = 4
var slump = Math.random ();
var talet = Math.Round (Slump * (A-1)) +1;
function Create () {
THIS.SRC = '
This.border = '
This.alt = '
}

b = New Array ()
for (var i=1 i<=a; i++) {B[i] = new Create ()}

B[1].SRC = "Reset.gif"
B[1].border = "0"
B[1].alt = "111"

B[2].SRC = "Back.gif"
B[2].border = "0"
B[2].alt = "222"

B[3].SRC = "Ie.gif"
B[3].border = "0"
B[3].alt = "333"

B[4].SRC = "Netscape.gif"
B[4].border = "0"
B[4].alt = "444"

var visa = "";
Visa = ' ';
</SCRIPT>

Place the following code anywhere in the HTML file:
<script language= "JavaScript" >
<!--Hide This script from the old browsers-
document.write (Visa)
-->
</script>
5. Play MIDI Music randomly

Place the following code between <script language= "JavaScript" >
<!--Hide from non JavaScript browsers
AM = 5
var ran = Math.random ();
var Talet = Math.Round (ran * (am-1)) +1;
function Create () {
THIS.SRC = '
}

c = New Array ()
for (var i=1 i<=am; i++) {C[i] = new Create ()}

C[1].SRC = "Hh1.mid"
C[2].SRC = "Hh2.mid"
C[3].SRC = "Hh3.mid"
C[4].SRC = "Hh4.mid"
C[5].SRC = "Hh5.mid"
var vismid = "";

Vismid + = ' <embed src= ' +c[talet].src+ ' width=0 height=0 ' + ' autostart=true ' + ' loop=2 ' + ' > ';
-->
</SCRIPT>
Place the following code between <body></body>:
<script language= "JavaScript" >
<!--Hide from non JavaScript browsers
document.write (Vismid);
-->
</script>
6. Random text

Place the following code between <script language= "JavaScript" >
<!--Hide
var a = Math.random () + ""
var rand1 = A.charat (5)
Quotes = new Array
QUOTES[1] = "Message #1"
QUOTES[2] = "Message #2"
QUOTES[3] = "Message #3"
QUOTES[4] = "Message #4"
QUOTES[5] = "Message #5"
QUOTES[6] = "Message #6"
QUOTES[7] = "Message #7"
QUOTES[8] = "Message #8"
QUOTES[9] = "Message #9"
Quotes[0] = "Message #10"
var quote = Quotes[rand1]
-->
</script>
Place the following code anywhere in the HTML file:
<script language= "JavaScript" >
<!--Hide
document.write ("<i>" + quote + "</i>")
-->
</script>
7. Random Connection

Place the following code between <script language= "JavaScript" >
<!--Hide from non JavaScript browsers
an = 5
var ran = Math.random ();
var Talet = Math.Round (ran * (an-1)) +1;
function Create () {
THIS.SRC = '

}

b = New Array ()
for (var i=1 i<=an; i++) {B[i] = new Create ()}

B[1].SRC = "<a href= ' http://netscape.yahoo.com/guide/Whats_cool.html ' >"
B[2].SRC = "<a href= ' http://www.disney.com ' >"
B[3].SRC = "<a href= ' http://www.peoplelink.com/' >"
B[4].SRC = "<a href= ' http://www.china-contact.com/cool/interest.htm ' >"
B[5].SRC = "<a href= ' HTTP://www.homeway.com.cn/html/homeway/navigator/index.html ' >"
var vis = "";
Vis + + b[talet].src;
-->
</SCRIPT>
Place the following code between <body></body>:
<script language= "JavaScript" >
<!--Hide from non JavaScript browsers
document.write (vis+ "Random link" + "</a>");
-->
</SCRIPT>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.