You are on page 1of 76

JavaScript

3-1

1.alert

2.
POP3

Navigator

(Navigator Object)

navigator.
navigator.

appCodeName
appName
appVersion
userAgent

->
->
->
->
( appName appVersion )

eval()
javaEnabled()
toString()
valueOf()

->()
->Java (True/False)
->
->

<Script>
with(document) {
write("=", navigator.appCodeName, "<br>");
write("=", navigator.appName, "<br>");
write("=", navigator.appVersion, "<br>");
write("=", navigator.userAgent, "<br>");
}
</script>

<script>
var str1 = navigator.appVersion;
var str2 = str1.split(";");
document.write("", str2[1], "<br>");
document.write("", str2[2], "<br>");
</script>

IE

<script>
isIE = (navigator.userAgent.indexOf("MSIE") != -1);
var yesorno = isIE? "": "";
document.write("" + yesorno +
" Microsoft Internet Explorer");
</script>

Screen

(Screen Object)

screen.
screen.

colorDepth
height
width

->
->
->


<script>

var width
var height
var color

= screen.width;
= screen.height;
= screen.colorDepth;

if
(color == 8)
else if (color == 16)
else if (color == 32)

color="256";
color="16";
color="32";

document.write("",
width, " * ", height,
"", color);
</script>

3-2

Window

(Window object)
1.
2.(focus)
3.
(alias)
ex. opener, parent, self, window, top

(1)

window.
window.()
self.
self.()
top.
top.()

//selfwindowframe
//top

(2)

parent.
//parent
parent.()
opener.
//opener
opener.()
.
.()

()

(1)

closed
defaultStatus
length
Frame
frames
name
opener
status

->
->
->
->frame
->frame
->
->
->

(2)

document
history
location

->document
->history
->location

frame
<Script>
//
//
if ( top.frames.length > 1 )
top.location= ""
</Script>

(1)

alert()
confirm()
prompt()
focus()
blur()
open()
close()
eval()

->
->
->
->
->()
->
->
->

(2)

resizeBy(x, y)
moveBy(x, y)
scroll(x,y)
print()
setTimeoout()
clearTimeout()
toString()
valueOf()

->XY
->XY
->
->
->()
->()
->
-->

prompt()

[window.]prompt("", "")

prompt

- prompt
<Script>
var bg=
prompt("\n -> 1 -> 2","1")
if
(bg == 1)
document.bgColor='#CCFFFF'
else if (bg == 2)
document.bgColor='#FFCCFF'
else
document.bgColor='#FFFFFF'

</Script>

- confirm & alert


<Script>
if (confirm("?"))
location.href = "sex.htm"
else
alert("!")
</Script>


1. Window.location.href =
2. Window.location =
3. location.href =
4. location =


<Script>
function grow(){
resizeBy( 50, 50)
}
function shrink(){
resizeBy( -50, -50)
}
</script>
<body onMouseOver=grow() onMouseOut=shrink()>
<H1></H1>
</body>


<Script>
function scrollIt() {
for (y=1; y<=1000; y++){
scroll(1,y)
}
}
</Script>
<body onDblClick=scrollIt()>
....
<br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br>
... The End ....
<body>


[ =] [Window.] open ([URL] [, ] [, ] )

1.

ex..close()

2.
ex.<a href=http://www.seed.net.tw target=>


height=number of pixels ->()
width= number of pixels ->()
left = number of pixels ->()
top = number of pixels ->()
fullscreen=yes or no
->
resizable=yes or no
->
menubar=yes or no
->
toolbar=yes or no
->
location=yes or no
->
directories=yes or no ->
status=yes or no
->
scrollbars=yes or no
->


1.
false(no)
2.
true(yes)

-
<form>
<input type=button value="(newWin)"
onClick="newWin=window.open('http://tw.yahoo.com/')"><P>
<input type=button value="height150"
onClick="open('http://tw.yahoo.com/','','height=150')"><P>
<input type=button value=""
onClick="open('http://tw.yahoo.com/','','toolbar=yes')"><P>
<input type=button value="(newWin)"
onClick=newWin.close()><P>
<input type=button value=""
onClick=window.close()><P>
</form>

-
<script>
// ;
open("http://tw.yahoo.com","_search")
</script>

3-3

100600

-
<Script>
function grow(){
resizeBy( 0, 150)
}
function shrink(){
resizeBy( 0, -150)
}
</script>
<body onMouseOver=grow() onMouseOut=shrink()>
here
</body>

<BODY onBlur="self.focus()">
<!-- onBlur -->
<!-- focus -->
here
</BODY>

Timer
[window.]setTimeout(, )

1.Timer

2.()
ex. 3000 milliseconds = 3 seconds

Timer ()
=
[window.]setTimeout(, )

Timer

[window.]clearTimeout()

- timer(1)
<script>
function timer() {
setTimeout("alert('3!')",3000)
}
</script>

<body>
<form>
<input type=button value="" onClick=timer()>
</form>
</body>

- timer(2)
<script>
var counter=0
upDate();
function upDate() {
counter ++
status = counter + ""
timer1 = setTimeout("upDate()",1000)
}
</script>
<body><form>
<input type=button value=""
onClick=clearTimeout(timer1)>
</form></body>


<script>
n = -1 ; bgFade() ;
function bgFade(){
n++
if (n <= 15){
var color = 0
if (n < 10)
{ color = 111111 * n }
else if (n == 10) { color = "AAAAAA" }
else if (n == 11) { color = "BBBBBB" }
else if (n == 12) { color = "CCCCCC" }
else if (n == 13) { color = "DDDDDD" }
else if (n == 14) { color = "EEEEEE" }
else if (n == 15) { color = "FFFFFF" }
document.bgColor = "#" + color
setTimeout("bgFade()",50)
}
}
</script>


<script>
var rgb=255;
function shine(){
rgb-=5;
document.all["alltext"].style.color =
"rgb(" + rgb + "," + rgb + "," + rgb +")";
if (rgb>0){
setTimeout("shine()", 100);
}
}
</script>
<body onload="shine()" id="alltext">
<font face="arial black" size="5">HUBERT</font>
</body>


<script>
mode1()
function mode1() {
document.bgColor='#CCFFFF'
setTimeout("mode2()",10000)
}
function mode2() {
document.bgColor='#FFCCFF'
setTimeout("mode1()",10000)
}
</script>


<li>
<font id="t1" style="display:none">new</font>
<script>
show()
function show() {
t1.style.display = ""
setTimeout("hide()",500)
}
function hide() {
t1.style.display = "none"
setTimeout("show()",500)
}
</script>


<script>
var count=0;
function changecolor(){
if (count%2==0)
neon.className = "greenglow";
else
neon.className = "pinkglow";
count++;
}
setInterval("changecolor()", 500);
</script>
<style>
.greenglow {filter:glow(color:green, strength:3); height:10pt}
.pinkglow {filter:glow(color:pink, strength:3); height:10pt}
</style>
<font id="neon" color="white" size="5" class="redglow">
</font>


<script>
var pos=-100;
function flyin(){
pos+=5;
id1.style.left = pos;
if (pos<30)
setTimeout("flyin()", 1);
}
</script>

<body onload="flyin()" >


<div id="id1" style="position:relative">
<a href="http://tw.yahoo.com/">YAHOO</a><br>
</div>
</body>


<script>
var pos=-100;
var idx=0;
var speed=1;
function flyin(){
pos+=5;
document.anchors[idx].style.left = pos;
if (pos<30)
setTimeout("flyin()", speed);
else if(idx!=document.anchors.length-1) {
idx+=1;
pos=-100;
setTimeout("flyin()", speed);
}
}
</script>
<!----- ----->


<!----- ----->
<style>
a {position:relative; left=-100}
</style>
<body onload="flyin()" >
<a href="http://tw.yahoo.com/"
name="yahoo">YAHOO</a><br>
<a href="http://www.google.com/"
name="google">Google</a><br>
</body>


<script>
var msg=" JavaScript !......."
var seq = 0
scroll()
function scroll() {
status = msg.substring(0, seq+1)
seq++
if ( seq >= msg.length ) seq = 0
setTimeout("scroll()",100)
}
</script>

3-4

1.

2.

3-5

1.

2.

3-6

1.
2.

3-7

1.20

100270
2.


<body>
<center>
<font id=num size=7 face=impact>0</font>
</center>
</body>
<script>
var sec = 0
count()
function count(){
num.innerHTML = sec++
setTimeout("count()",1000)
}
</script>

3-8

(history object)
1. history
URL
2. (list)
3. history
ex. IE ->
/
NC ->
(go)

history.
history.()

current
length
next
previous

->URL
-> historyURL
-> historyURL
-> historyURL

back()
forward()
eval()
go()
toString()
valueOf()

->URL
->URL
->
->URL
->
->

- history
<body>
<form>
<input type=button value="" onClick=history.back()>
<input type=button value="" onClick=history.forward()>
</form>
</body>

(location object)
URL(Universal Resource Locator)

protocol//host:port/pathname#hash?search

URLWWW
(address scheme)

[.] location [.]


[.] location .()

protocol
host
port
hostname
pathname
hash
search
href

->URL()
->(/IP)
->URL
->URL host:port
->URL
->URLanchor
->URL
->URL

eval()
reload()
replace()
toString()
valueOf()

->
->
->
->
->

- location(1)
<Script>
with (document) {
write("<a href=javascript:location.reload()></a><p>")
write("<a href =javascript:location.replace('http://www.seed.net.tw')>
SeedNet</a><p>")
write("SeedNet<p>".link('http://www.seed.net.tw'))
write("<a href='http://www.seed.net.tw'>SeedNet</a><p>")
}
</Script>
<body>
<a href="http://www.seed.net.tw">SeedNet</a>
</body>

- location(2)
<body>
<a href='#' onMouseOver=location.replace('http://www.seed.net.tw')>
SeedNet</a><p>
<a href='#' onMouseOver=location.href='http://www.seed.net.tw'>
SeedNet</a><p>
<a href='#' onMouseOver=window.location='http://www.seed.net.tw'>
SeedNet</a>
</body>

frame
<Script>
//
//

if (parent.location.href != window.location.href)
parent.location.href = window.location.href
</Script>

3-9

hint: view-source:location.href

- location(3)
<Form>

<input type=button value=Seednet


onClick=location='http://www.seed.net.tw'>
<input type=button value=Hinet
onClick=location='http://www.hinet.net'>
</Form>


<FONT SIZE=7
onClick="location='http://www.seed.net.tw'"
style="cursor=hand"
>seedNET</FONT>

CSS


<FONT SIZE=7
onClick="location='http://www.seed.net.tw'"
style="cursor=hand"
onMouseover="this.style.color='red'"
onMouseout="this.style.color='black'"
>seedNET</FONT>

CSS


<script>

setTimeout("location = 'http://tw.yahoo.com' ",5000)


</script>
<body>
<center>

<H2>http://tw.yahoo.com</H2>

</center>
</body>

(2)
<body>
<center>

<H2>http://tw.yahoo.com</H2>
</br>
<font id=num size=7 face=impact>5</font>
</center>
</body>

(2)

<script>
var sec = 4
setInterval("countDown()",1000)
function countDown(){
if (sec >= 0)
num.innerHTML = sec-else
location = "http://tw.yahoo.com"
}
</script>


<img name=banner src=banner1.gif onClick=GoSponsor()>
<SCRIPT>
var sponsor = 1
setInterval(" rotate()",5000)
//
function GoSponsor() {
if (sponsor==1) location="http://www.hinet.net"
if (sponsor==2) location="http://www.seed.net.tw"
}
function rotate() {
if (++sponsor > 2)
sponsor = 1
document.banner.src = "banner" + sponsor + ".gif"
}
</SCRIPT>

You might also like