javascript在不同页面之间传值示例

来源:互联网 发布:大数据分析的算法 编辑:程序博客网 时间:2024/06/09 02:52
主页面:
1.html
<button id="button1" onclick="window.open('1.html','name','height=200,width=150');"></button>
<script>

var newwindow = '';

function popitup(url) {
    if (!newwindow.closed && newwindow.location) {
        newwindow.location.href = url;
    }
    else {
        newwindow=window.open(url,'name','height=200,width=150');
        if (!newwindow.opener) newwindow.opener = self;
    }
    if (window.focus) {newwindow.focus()}
    return false;
}

popitup('2.html');
</script>

弹出页面:
<html>
<body>
2.html<br/>
<button onclick="opener.button1.value='new value'"></button>
<body>
</html>

解释:
主要应用opener定位弹出窗口的父窗口。
原创粉丝点击