易截截图软件、单文件、免安装、纯绿色、仅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获取各种浏览器可见窗口大小

搞了大半天,总算弄明白了为何用document.body.clientHeight,document.body.offsetHeight都没有办
法获取网页可见区域的正确值,原来罪魁祸首是W3C定义的标准!!在新定义出来的标准下
document.documentElement.clientHeight在IE和火狐里都能获取正确值,下面一篇文章详细介绍了获取各种浏览器可见
窗口大小这方面的差 ......

无缝滚动新闻的Javascript源代码

重点在于function scroll(),function clipShow()及以下for循环。
无缝滚动新闻的Javascript源代码,放在这里,有需要的时候可能用得上:
//CSS样式
<style>
.new_newsT{
 padding-top: 10px;
 padding-bottom: 8px;
}
.new_newsT  .list {
 CLEAR: both; MARGIN: 0px 6px 0px 10px
} ......

对于JavaScript的 Stack overflow at line 错误总结

对于JavaScript的 Stack overflow at line 错误总结
该错误只在IE中出现,出现该提示的原因主要有两种:
     1. 重定义了系统的触发事件名称作为自定义函数名如:  onclick / onsubmit ...  都是系统保留的事件名称,不允许作为重定义函数名称。
     2. ......

JavaScript的日期处理

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

JAVASCRIPT访问父窗口的变量或方法


AA.HTM
-------------------------------------
<!--
showModalDialog函数的使用   (转)     
本范例可以实现弹出一个模态窗口,并演示了两种接收和传递参数的方法,同时可以接受模态窗口返回的多个变量   
-->
<html>    &nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号