<html>
<head>
<title>JavaScript Function</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script type="text/javascript">
<!--
function $(obj){
return document.getElementById(obj);
}
function sum(a,b){
a=parseInt(a);
b=parseInt(b);
if(isNaN(a) || isNaN(b)){
try{
throw new Error("Arguments are not numbers");
}catch(e){
$("objContent").innerHTML = e.description;
}
}
return a+b;
}
function setCookie(cookieName,cookieValue){
var expires = new Date();
expires.setTime(expires.getTime() + 3 * 30 * 24 * 60 * 60 * 1000); // 三个月 x 一个月当作 30 天 x 一天 24 小时 x 一小时 60 分 x 一分 60 秒 x 一秒 1000 毫秒
document.cookie = cookieName + '=' + escape(cookieValue) + ';expires=' + expires.toGMTString();
$("objContent").innerHTML = document.cookie;
}
function getCookie(cookieName) {
var cookieString = document.cookie;
var start = cookieString.indexOf(cookieName + '=');
if (start == -1) // 找不到Cookie Name
return null;
start += cookieName.length + 1;
var end = cookieString.indexOf(';', start);
if (end == -1) {
$("objContent").innerHTML = unescape(cookieString.substring(start));
return unescape(cookieString.substring(start));
}
$("objContent").innerHTML = unescape(cookieString.substring(start, end));
return unescape(cookieString.substring(start, end));
}
function delCookie(cookieName,cookieValue){
var expires = new Date();
expires.setTime(expires.getTime() - 1);
document.cookie = cookieName + '=' + cookieValue + ';expires=' + expires.toGMTString();
$("objContent").innerHTML = document.cookie;
}
function Is() {
var agent = navigator.userAgent.toLowerCase();
this.major = parseInt(navigator.appVersion); //主版本号
this.minor = parseFloat(navigator.appVersion);//全版本号
this.ns = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
this.ns2 = (this.ns && (this.major == 3)); //是否 Netscape 2
this.ns3 = (this.ns && (this.major == 3)); //是否 Netscape 3
this.ns4b = (this.ns && (this.minor < 4.04)); //是否 Netscape 4 低版本
this.ns4 = (this.ns && (this.major >= 4)); //是否 Netscape 4 高版本
this.ie = (agent.indexOf('msie') != -1); //是否 IE
this.ie3 = (this.ie && (this.major == 2)); //是否 IE 3
this.ie4 = (this.ie && (this.major >= 4)); //是否 IE 4
this.ie5 = (this.ie && (this.major >= 5)); //是否 IE 5
this.ie6 = (this.ie && (this.major >= 6)); //是否 IE 6
this.ie7 = (this.ie && (this.major >= 7)); //是否 IE 7
this.op3 = (agent.indexOf('opera') != -1); //是否 Opera 3
this.win = (agent.indexOf('win')!=-1); //是否 Windows 版本
this.mac = (agent.indexOf('mac')!=-1); //是否 Macintosh 版本
this.unix = (agent.indexOf('x11')!=-1); //是否 Unix 版本
}
function getError(){
var txt = '';
try{
error();
}catch(e){
txt = "There was an error on this page.<br/>";
txt += "Error name: " + e.name + "<br/>";
txt += "Error number: " + e.number + "<br/>";
txt += "Error message: " + e.message + "<br/>";
txt += "Error description: " + e.description + "<br/>";
$("objContent").innerHTML = txt;
}
}
function getNavigator(){
var txt = '';
with(navigator){
txt = "appCodeName: " + appCodeName + "<br/>//返回浏览器的“码名”(?),流行的 IE 和 NN 都返回 'Mozilla'。<br/>";
txt += "appName: " + appName + "<br/>//返回浏览器名。IE 返回 'Microsoft Internet Explorer',NN 返回 'Netscape'。<br/>";
txt += "appVersion: " + appVersion + "<br/>//返回浏览器版本,包括了大版本号、小版本号、语言、操作平台等信息。<br/>";
txt += "platform: " + platform + "<br/>//返回浏览器的操作平台,对于 Windows 9x 上的浏览器,返回 'Win32'(大小写可能有差异)。<br/>";
txt += "userAgent: " + userAgent + "<br/>//返回以上全部信息。例如,IE5.01 返回 'Mozilla/4.0 (compatible; MSIE 5.01; Windows 98)'。<br/>";
txt += "javaEnabled(): " + javaEnabled() + "<br/>//返回一个布尔值,代表当前浏览器允许不允许 Java。<br/>";
}
var is = new Is();
if(is.ie7){
txt += "This is ie7.";
}
else{
txt += "This isn't ie7.";
}
$("objContent").innerHTML = txt;
}
function getScreen(){
var txt = '';
with(screen){
txt = "width: " + width + "px<br/>";
txt += "height:" + height + "px<br/>";
txt += "availWidth: " + availWidth + "px<br/>";
txt += "availHeight: " + availHeight + "px<br/>";
txt += "colorDepth: " + colorDepth + "px<br/>//- 1:黑白;8:256色;16:增强色;24/32:真彩色";
}
$("objContent").innerHTML = txt;
}
function getWindow(){
var txt = '';
window.status = "Welcome to you";
window.name = "javascript example"
txt = "window object:";
txt = "name: " + window.name + "<br />//name 窗口的名称,由打开它的连接(<a target=...>)或框架页(<frame name=...>)或某一个窗口调用的 open() 方法决定。<br/>";
txt += "status: " + window.status + "<br />//status 指窗口下方的“状态栏”所显示的内容<br/>";
txt += "opener: " + window.opener + "<br />//opener 用法:window.opener;返回打开本窗口的窗口对象。<br/>";
txt += "self: <a href=javascript:self.close()>关闭窗口</a><br />//self 指窗口本身,它返回的对象跟 window 对象是一模一样的。最常用的是self.close(),放在<a>标记中。<br/>";
txt += "parent: <a href=javascript:parent.name>parent.name</a><br />//parent 返回窗口所属的框架页对象.<br/>";
txt += "top: <a href=javascript:top.name>top.name</a><br />//top 返回占据整个浏览器窗口的最顶端的框架页对象。<br/>";
txt += "open(): <a href=javascript:open('','_blank','width=400,height=100,menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes')>open('','_blank','width=400,height=100,menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes')</a>;<br/>";
txt += "close(): <a href=javascript:close()>关闭窗口</a><br />//close() 关闭一个已打开的窗口。用法:window.close() 或 self.close():关闭本窗口;<窗口对象>.close():关闭指定的窗口。<br/>";
txt += "如果该窗口有状态栏,调用该方法后浏览器会警告:“网页正在试图关闭窗口,是否关闭?”然后等待用户选择是否;如果没有状态栏,调用该方法将直接关闭窗口。<br/>";
txt += "blur(): <a href=javascript:blur()>blur()</a><br />//blur() 使焦点从窗口移走,窗口变为非活动窗口。<br/>";
txt += "focus(): <a href=javascript:focus()>focus()</a><br />//focus() 是窗口获得焦点,变为“活动窗口”。不过在 Windows 98,该方法只能使窗口的标题栏和任务栏上的相应按钮闪烁,提示用户该窗口正在试图获得焦点。<br/>";
txt += "scrollTo(): <a href=javascript:scrollTo(100,100)>scrollTo(100,100)</a><br />scrollTo(100,100) 用法:[<窗口对象>.]scrollTo(x, y);使窗口滚动,使文档从左上角数起的(x, y)点滚动到窗口的左上角。<br/>";
txt += "scrollBy(): <a href=javascript:scrollBy(100,100)>scrollBy(100,100)</a><br />//scrollBy(100,100) 用法:[<窗口对象>.]scrollBy(deltaX, deltaY);使窗口向右滚动 deltaX 像素,向下滚动 deltaY 像素。如果取负值,则向相反的方向滚动。<br/>";
txt += "resizeTo(): <a href=javascript:resizeTo(800,600)>resizeTo(800,600)</a><br />//resizeTo(800,600) 用法:[<窗口对象>.]resizeTo(width, height);使窗口调整大小到宽 width 像素,高 height 像素。<br/>";
txt += "resizeBy(): <a href=javascript:resizeBy(100,100)>resizeBy(100,100)</a><br />//resizeBy(100,100) 用法:[<窗口对象>.]resizeBy(deltaWidth, deltaHeight);使窗口调整大小,宽增大 deltaWidth 像素,高增大 deltaHeight 像素。如果取负值,则减少。<br/>";
txt += "alert(): <a href=javascript:alert()>alert()</a><br />//alert() 用法:alert(<字符串>);弹出一个只包含“确定”按钮的对话框,显示<字符串>的内容,整个文档的读取、Script 的运行都会暂停,直到用户按下“确定”。<br/>";
txt += "confirm(): <a href=javascript:confirm()>confirm()</a><br />//confir