1.js页面特效大全

来源:互联网 发布:雅马哈网络经销商 编辑:程序博客网 时间:2024/06/06 21:06
<!DOCTYPE html><html dir="rtl">    <head>        <!--1.3页面自动刷新--为了及时反映站点数据变化-->        <!--重点:meta元素,其http-equiv属性设置为refresh会自动刷新当前页面            content可以设置刷新的时间间隔 URL表示刷新后的页面地址        -->        <meta charset="UTF-8" http-equiv="refresh" content="3;url=http:www.google.com">        <!--1.10定义网页的关键字 SEO优化-->        <!--重点:meta元素,content属性设置网站包含的关键字-->        <meta name="keywords" content="net,enterprise,ERP,c#" />        <!--1.13禁止将页面加入缓存-->        <!--重点:meta元素,http-equiv相当于http头部 传回一些有用信息,帮助显示网页 content中的内容就是各个参数的值-->        <meta http-equiv="Pragma" content="on-cache" />        <title>第一章页面特效</title>    </head>    <script language="JavaScript">        //1.2页面自动最大化--为了方便用户的操作        //定位左上角        self.moveTo(0,0);        //调整屏幕        //重点:screen的availWidth/availHeight属性可以设置屏幕的最大宽度和最大高度        self.resizeTo(screen.availWidth,screen.availHeight);        //1.4页面的后退,前进,刷新        //重点:history对象,用来存储浏览器的历史数据,其参数为正数时候表示前进,为负数时表示后退        function back(){            history.go(-1);        }        function forward(){            history.go(+1);        }        function refresh(){            history.go(-0);        }        //1.5保护页面源代码--屏蔽对于源代码的查看        //原理:先将文档内容写入到一个变量中去,在然后清空,最后显示旧内容        function clear(){            Source=document.body.innerHTML;//获取当前页面内容            document.open();//打开文档            document.write("代码已经被屏蔽掉");//输出提示内容            document.close();//关闭文档            document.title="看不到源代码";//文档标题            document.body.innerHTML=Source;//重新写入旧内容        }        //1.6保护自己的网页不被放入框架        //重点:对于层的判断 可以被框架加载的页面不能位于"top"层        if(self!=top){            top.location=self.location;//不为顶层则把当前页面设置为顶层        }        //1.7打印页面出错的原因        //重点:try-catch        function getError(){            try{                x=new test;//产生错误            }catch(e){                document.write(e.description);//打印错误结果            }        }        //1.9倒计时载入当前页面        startday=new Date();//获取当前时间        clockStart=startday.getTime();        function initStopwatch(){            var myTime=new Date();            var timeNow=myTime.getTime();            var timeDiff=timeNow-clockStart;//获取间隔时间            this.diffSecs=timeDiff/1000;//时间以毫秒为单位            return(this.diffSecs);//返回间隔秒数        }        function getSecs(){            var mySecs=initStopwatch();            var mySecs1=""+mySecs;            mySecs1=10-eval(mySecs1.substring(0,mySecs1.indexOf(".")))+"秒";            document.form1.timespent.value=mySecs1;            window.setTimeout("getSecs()",1000);        }        //1.15判读页面是否添加了W3C声明        //重点:document.compatMode的变量的值        if(document.compatMode=="CSSlCompat"){            alert("本文档添加了W3C说明");        }else{            alert("本文档没有添加W3C说明")        }        //1.17以频道模式打开打开页面        //解释:打开一些警告或者说明的页面时,这种模式称为频道模式(只有一个标题栏和按钮)        //重点:使用了window.open()方法,指定了参数channelmode        function channel(){            window.open("以频道模式打开页面2.htm","_blank","channelmode")        }        //1.18自动识别网页类型        //重点字符串的indexOf()方法        URL=window.location.href;//获取URL地址        ishtm=(URL.indexOf('.htm')>-1);//判断地址中包含的字符        ishtml=(URL.indexOf('.html')>-1);        isshtml=(URL.indexOf('.shtml')>-1);        isphtml=(URL.indexOf('.phtml')>-1);        isaspx=(URL.indexOf('aspx')>-1);        //1.19在页面中动态添加脚本        //createElement()        o=document.createElement("script");//动态创建script元素        o.text="alert('test!')";//弹出提示信息        document.documentElement.childNodes[0].appendChild(o);//将脚本添加到页面中去        //1.24使用js传递页面参数        function getArgs(params,paramName){            var argIndex=params.indexOf("?");//获取?所在的位置            var arg=params.substring(argIndex+1);//获取?后面的字符串            var varArg="";            args=arg.split('&');//参数分割            for(var i=0;i<args.length;i++){                str=args[i];                var arg=str.split('=');                if(arg.length<=1) continue;//无参                if(arg[0]==paramName){                    varArg=arg[i];//获取指定参数值                }            }            return varArg;        }        function PageParm(){            var myname=getArgs(window.location.href,"name");            document.write("你的请求参数是:"+myname)        }        //1.25冻结页面 页面被冻结以后,点击页面么有任何反应        function freeze(){            alert("对不起,死机了!!!");//提示            window(true){//进入死循环                window.history.back(-1);//后退一格            }        }    </script>    <!--1.16屏蔽暂时不需要的脚本-->    <!--重点:noscript-->    <noscript>        <script>alert("看看能不能展示");</script>    </noscript>    <!--1.22页面嵌入播放器-->    <!--重点:object组件的使用 微软为浏览器提供的拓展,使用object组件调用-->    <object id="play" width="450" height="150" classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6">        <param name="URL" value="http://go.microsoft.com/fwlink/?LinkID=91175"/>        <param name="rate" value="1"/>        <param name="balance" value="0"/>        <param name="currentPosition" value="0"/>        <param name="defaultFrame" value=""/>        <param name="playCount" value="1000"/>        <param name="autoStart" value="0"/>        <param name="currentMarker" value="0"/>        <param name="invokeURLs" value="-1"/>        <param name="baseURL" value=""/>        <param name="volume" value="1.00"/>        <param name="mute" value="0"/>        <param name="uiMode" value="full"/>        <param name="stretchToFit" value="0"/>        <param name="windowlessVideo" value="0"/>        <param name="enabled" value="-1"/>        <param name="enableContextMenu" value="-1"/>        <param name="fullScreen" value="0"/>        <param name="SAMTStyle" value=""/>        <param name="SAMTLang" value=""/>        <param name="SAMTFilename" value=""/>        <param name="captioningID" value=""/>    </object>    <!--1.14离开页面时弹出对话框-->    <!--重点:body的onUnload事件事件,在离开页面时候触发.一般用在body或者frameset标签上-->    <body onload="clear()" onload="getError()" onload="window.setTimeout('getSecs()',1)" bgcolor="#ffffff" bgcolor="#fef4d9"        onunload="window.alert('谢谢你的光临!欢迎下次再来!')">        <center>10秒后将加载页面:        <form name=form1><input size=9 name=timespent></form>        </center>        <!--1.8一个页面调用其他页面-->        <!--重点:object标签.text/x-scriptlet是IE的一个插件  data表示要加载的数据-->        <object type="text/x-scriptlet" width="150" height="100" data="http://baidu.com"></object>        <marquee>测试下能否看到源代码</marquee>        <!--1.1页面的反向显示-->        <!--重点: dir的属性rtl:right to left-->        这是一段未达的历史<br />        来自全世界的瞩目和掌声        <input type="button" onclick="back()" value="后退"/>        <input type="button" onclick="forward()" value="前进"/>        <input type="button" onclick="refresh()" value="刷新"/>        <script>            //1.11进入页面是弹出欢迎对话框            //原理:利用js逐行解释逐行执行的功能            alert("欢迎进入在线考试系统,答题期间请不要接打电话!")        </script>        <noscript>            <!--1.12禁止页面另存为-->            <!--重点:noscript是HTML元素,不支持js会展示 iframe表示框架,其数据源是所有的HTML-->            <!--二者结合就禁止了页面的另存为行为-->            <iframe src=*.html></iframe>        </noscript>        <input type="text" name="txt1" value="this is test!"/>        <input type="button" value="转换文本" onclick="javascript:changeCase(txt1)"/>        <script>            if(isphtml){                document.write("这是一个.phtml页面");            }else if(isshtml){                document.write("这是一个.isshtml页面");            }else if(ishtml){                document.write("这是一个.html页面");            }else if(ishtm){                document.write("这是一个.htm页面");            }else if(isaspx){                document.write("这是一个.aspx页面");            }else{                document.write("无法识别该类型的文件");            }        </script>        <!--1.20使用javascript随机修改页面的标题-->        <!--onload事件只有在页面加载的时候title才会改变-->        <script>            var til=new Array(5);            var til[0]="第一个标题";            var til[0]="第二个标题";            var til[0]="第三个标题";            var til[0]="第四个标题";            var til[0]="第五个标题";            var indextitle=Math.floor(Math.random()*til.length);//获取一个随机数            onload=function chaTitle(){                var curTitle=til[indextitle];                window.document.title="-"+curTitle;            }        </script>        <!--1.21判断页面加载完成-->        <!--iframe框架是在当前页面嵌入另外一个页面 ,框架+onload方法-->        <iframe onload=alert("加载完成") src="http://sina.com.cn"></iframe>        <!--1.23设置指定页面为主页-->        <!--重点:behavior属性设置或者检索对象的DHTML行为-->        <a href="#" onclick="this.style.behavior='url(#default#homepage)'this.setHomePage('http://www.google.com');"></a>        <input type="button" value="Freeze"  onclick="freeze()"/>    </body></html>
0 0