1、主页面

<html>
<body>
<script type="text/javascript">
    var _callback;
    function exec(callback) {
        _callback = callback;
        document.getElementById("txtResult").value = (new Date()).toLocaleString();
    }

    function subpage() {
        if (_callback) {
            try {
                _callback("我要给子页面赋值123");
            } catch (e) {
            }
        }
    }
</script>
<input type="button" value="打开窗口" onclick="window.open('children.htm')" />
<input type="button" value="回传" onclick="subpage()" />
<input type="text" id="txtResult" />
</body>
</html>

2、子页面

<html>
<body>
<script type="text/javascript">
    function toppage() {
        opener.exec(exec1);
    }

    function exec1(msg) {
        document.getElementById("txtResult").value = msg;
    }
</script>
<input type="button" value="主页面方法" onclick="toppage()" />
<input type="text" id="txtResult" />
</body>
</html>

 

posted on 2015-06-05 14:31  王洪洪  阅读(319)  评论(0编辑  收藏  举报