由子未

向上人生路

导航

常用DHTML

DHTML

window:控制浏览器

  <script language="javascript">

  window.defaultStatus="defaultd";

  window.status="starus";

  window.name="window_prop";

  function cr()

  {  var str="";

     window.status="123";

     str+="状态栏:" + window.status;

     str+="<br>引用窗口是否关闭:" + window.closed; 

     str+="<br>窗口名称:" + window.name;

     str+="<br>客户区左上角距屏幕左上角X轴距;" +

window.screenLeft;

     str+="<br>客户区左上角距屏幕左上角Y轴距:" +

window.screenTop; 

     d1.innerHTML=str;  }

</script>

<button onclick="cr()">+ click +</button>

<div id="d1"></div>

window.frames:框架

  <frameset cols=20%,*>

<frame src="a.htm">

<frame name="bfr" src="b.htm" >

</frameset>

<script language="javascript">

if ( window.frames != null )

{  for ( i = 0; i< window.frames.length; i++ )

//length表示窗口个数

  window.alert ("子窗口 " +i+ " 的名称为 "+window.frames(i).name);

  }

</script>

navigate:链接到指定url,向超链接一样

  function on()

{  window.navigate("this.htm");  }

confirm_prompt_colse:对话框和关闭浏览器

  function al()

{  var a=window.prompt("请输入内容","0-1")

     var b=window.confirm(a + "是否关闭浏览器?")//返回布尔值

     if(b == true)

     {  window.opener=null;

        //不让浏览器提示直接关闭

        window.close();  }

        //close后要括号

     else

     {alert("你选择不关闭浏览器");}    }

window.open:

  {  window.open("颜色选择器.htm","_blank","directories=1," +

               "fullscreen=1,location=1,menubar=1," +

              "resizable=0,scrollbars=0,status=0,toolbar=1",1);}

  !:括号里第一个设置url,第二个设置打开方式,第三个设置特性,第四个

设置是否替换历史记录

  打开方式/3:

    _blank:新窗口

_self_parent:原窗口

  特性/10:

top:高  width:宽  directories:链接栏  location:地址栏

menubar:菜单栏  toolbar:工具栏  fullscreen:满屏,不显示任何栏

resizable:调整大小  scrollbars:滚动条  channelmode:最大化

document.bgcolor:设计背景颜色

  document.bgcolor=”red”

document.cookie:

  function to(cname)

{  var ti=new Date();

     var st="name=" + cname + ";expires=" + ti.toUTCString();

  //expires设置cookie过期时间,是个被cookie执行的参数

       st=st.replace("18","19");

  //为了让cookie生效,要把过期时间更改为当前时间toUTCString()之后

     alert(st)

     document.cookie=st;

     //把st的值写入cookie

     alert(document.cookie);

     var spco=document.cookie.split(";");

     alert(spco.length)

     //length是指一个数组或对象的个数或长度

     for(i=0;i<spco.length;i++)

     {  var va=spco[i];

        document.write(va + "<br>");  } 

     return;  }

<button onclick="to('liaoli')">click</button>

document_all:提取document的所有标签

  var doa=document.all.length;

  alert("共有" + doa + "个标签.");

var bova="";

for(i=0;i<doa;i++)

{  bova+="\r"+document.all[i].tagName;  }

   //all[i]不是表示第几个,i是第几个.all[i]表示第几个里的内容

   //\r表示对话框里的换行

   //tagName表示标签名,返回的标签名不包括< >符号

   alert(bova);

document_anchors:提取全部带有name或id的a标签

  var dan=document.anchors.length;

  alert("共有" + dan + "个<a>标签.");

var bovan="";

for(i=0;i<dan;i++)

{  bovan+="\r" + document.anchors[i].tagName;  }

alert(bovan);

document_writeln:写入一行并回车,在IE中测试回车变成了一空格

document_open:向浏览器写入html标签

  var douop=document.open("text/html","replace");

   //括号里的内容是固定的写法,只要记住就可以

   //不会打开新的窗口,只会改变现在窗口的内容

   var sm="<html><head><title>

document_open</title><body>holle</body></html>";

   douop.write(sm);

   douop.close;

navigator:提取系统和浏览器信息

  语法:navigator.userAgent

location:

  属性:

  hash 设置或获取 href 属性中在井号“#”后面的分段。

host 设置或获取 location 或 URL 的 hostname 和 port 号码。

hostname 设置或获取 location 或 URL 的主机名称部分。

href 设置或获取整个 URL 为字符串。

pathname 设置或获取对象指定的文件名或路径。

port 设置或获取与 URL 关联的端口号码。

protocol 设置或获取 URL 的协议部分。

search 设置或获取 href 属性中跟在问号后面的部分。

方法:

assign 装入新的 HTML 文档。

reload 重新装入当前页面。

replace 装入指定 URL 的另外文档来替换当前文档和历史记录

  location.href="location.htm#Rt?Yu"

document.write("hash的值为:" + location.hash + "<br>");

function as()

{  location.assign("history.htm");  }

function repl()

{  location.replace("history.htm");  }

function relo()

{  location.reload(true);  }

posted on 2009-03-01 17:01  Rayleigh  阅读(271)  评论(0编辑  收藏  举报