易截截图软件、单文件、免安装、纯绿色、仅160KB

javascript调用父窗口的函数和变量


javascript调用父窗口的函数和变量
发布日期:2008-05-28最近更新:2008-05-28来源:BHCODE作者:
web开发的时候,有时候需要使用其他页面上写好的javasript函数、变量。如弹出窗口需要使用父窗口中的函数,框架1需要使用框架2中的函数。
调用函数、变量的方法一样,都是需要首先获得你需要调用的函数所在的window对象,然后通过window.method()或者 window.variable 来调用。
下面的示例演示了一个弹出窗口如何调用起父窗口中的方法和变量。
父窗口:1.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
var theHelloStr = "Hello all.";
function sayHello()
{
    alert("hello, method");
}
function openBtnClicked()
{
    var newwin=window.open('2.html',"test","toolbar=no,location=no,top=100,left=100,directories=no,status=yes,menubar=no,scrollbars=yes,location=no,resizable=yes,width=300,height=200");
    newwin.focus();
}
function sayHello2()
{
    window.sayHello();
}
</script>
</head>
<body>
<input type="button" name="openBtn" value="打开窗口" onclick="openBtnClicked()" />
</body>
</html>
弹出窗口:2.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function btn1Clicked()
{
    window.opener.sayHello();
}
function btn2Clicked()
{
    var helloMsg = window.opener.theHelloStr;
    alert(helloMsg);
}
</script>
</head>
<


相关文档:

javascript Date日期对象 (转)

创建一个日期对象:
var objDate=new Date([arguments list]);
参数形式有以下5种:
   new Date("month dd,yyyy hh:mm:ss");
   new  Date("month dd,yyyy");
   new  Date(yyyy,mth,dd,hh,mm,ss);
   new Date(yyyy,mth,dd);
   new Date(ms); ......

javascript:void(0)

  javascript:void(0)
   刚开始都不知道是啥意思
  其实就是一个死链接,什么事情都不做。
  <a id="link_${user.account}" href="javascript:void(0);" onclick="changSubmit();" style="cursor:pointer;height:25px;width:60px;margin-top:10px;">发送email</a>
  这句 ......

一句话JavaScript表单验证代码

表单的客户端javascript验证有各种各样的写法,登录为form的onsubmit事件或submit按扭写一个函数。对于小表单(只有一两个表单域的表单)就不必再专门再用javascript写一个验证函数了,只需要在form的onsubmit事件里加上:
onsubmit=”return domainname.value==”?(alert(’请输入搜索内容’),false ......

JavaScript的日期处理

var myDate = new Date();
myDate.getYear();        //获取当前年份(2位)
myDate.getFullYear();    //获取完整的年份(4位,1970-????)
myDate.getMonth();       //获取当前月份(0-11,0代表1月)
myDate.getDate();    ......

javascript refresh page 几种页面刷新的方法

Javascript刷新页面的几种方法:
1    history.go(0)
2    location.reload()
3    location=location
4    location.assign(location)
5    document.execCommand('Refresh')
6    window.navigate(location)
7& ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号