从网上找到的子父窗口操作
一、Iframe 篇
//&&&&&&&&&&&&&&&&&&&&公共方法开始&&&&&&&&&&&&&&&
//父对象得到子窗口的值
//ObjectID是窗口标识,ContentID是元素ID
function GetValue(ObjectID,ContentID)
{
var IsIE = (navigator.appName == 'Microsoft Internet Explorer')
if(IsIE)
{//如果是IE
alert(document.frames(ObjectID).document.getElementById(ContentID).innerHTML);
}
else
{//如果是FF
alert(document.getElementById(ObjectID).contentDocument.getElementById(ContentID).innerHTML);
//FF下不支持innerText; 下面是解决方法
//if(document.all){
// alert(document.getElementById('div1').innerText);
//} else{
// alert(document.getElementById('div1').textContent);
//}
}
}
//父对象向子窗口赋值
//ObjectID是窗口标识,ContentID是元素ID
function SetValue(ObjectID,ContentID)
{
var IsIE = (navigator.appName == 'Microsoft Internet Explorer')
if(IsIE)
{//如果是IE
document.frames(ObjectID).document.getElementById(ContentID).innerHTML="我是IE下通过父窗口赋值过来的";
}
else
{//如果是FF
document.getElementById(ObjectID).contentDocument.getElementById(ContentID).innerHTML="我是FF下通过父窗口赋值过来的";
}
}
//&&&&&&&&&&&&&&&&&&&&公共方法结束&&&&&&&&&&&&&&&
1.父窗口对子窗口操作
刷新:
document.getElementById("IframeID").src=document.getElementById("IframeID").src+"?_="+Math.random();
上面这种方法有时需要对“src”属性处理一下。
取值:
//父窗口取子窗口的值
GetValue("Iframe1","IframeDiv");
赋值:
//父窗口设置窗口元素的值;
SetValue("Iframe1","IframeDiv");
2.子窗口操作父窗口
刷新:
(1)、window.parent.location.href=window.parent.location.href;
(2)、window.parent.location.reload();
(3)、大家可以补充
取值:
alert(window.parent.document.getElementById("IframeDiv").innerHTML);
赋值:
window.parent.document.getElementById("IframeDiv").innerHTML="我是从子窗口IFRAME传过来的值";
关闭:
window.parent.opener=null;//如果不加这句,会提示关闭询问窗口;
window.parent.close();
二、window.open 篇
1.父窗口对子窗口操作
打开:
var win=null;
win=window.open("Open.html","win","width=200,height=200");
最大化:
//窗口最大化
function SonMaximize()
{
if(win&&win.open&&!win.closed)
{
win.moveTo(-4,-4);
win.resizeTo(screen.availWidth+8,screen.availHeight+8);
}else{
alert('还没有打开窗口或已经关闭');
}
}
最小化:
//窗口最小化
function SonMinimize()
{
if(win&&win.open&&!win.closed)
{
win.resizeTo(0,0);
win.moveTo(0,window.screen.width);
}else{
alert('还没有打开窗口或已经关闭');
}
}
关闭:
//关闭窗口
function CloseSon()
{
if(win&&win.open&&!win.closed)
{
win.opener=null;
win.close()
}else{
alert('还没有打开窗口或已关闭') ;
}
}
刷新:
//刷新
function RefreshSon()
{
if(win&&win.open&&!win.closed)
{
win.location.reload();
win.focus();
}else{
alert('窗口还没有打开或已关闭');
}
}
查看窗口大小:
function ViewSonSize()
{
if(win&&win.open&&!win.closed)
{
alert(win.document.body.clientWidth+'*'+win.document.body.clientHeight);
win.focus();
}else
{
alert(' 还没有打开窗口或者已关闭');
}
}
取值:
alert(window.document.getElementById("OpenDiv").innerHTML);
赋值:
win.document.getElementById("OpenDiv").innerHTML="我是从父窗口中传过来的值";
2.子窗口操作窗口
刷新:
window.opener.location.reload();
//下面这种方法也可以
//window.parent.location.href=window.parent.location.href;
关闭本窗口:
//关闭本窗口
function CloseWindow()
{ //window.opener.opener=null;
window.close();
}
关闭父窗口:
//关闭父窗口
function CloseParent()
{ //火狐下不起作用,如果要想起作用。用下面的方法
//开firefox,在地址栏输入about:config
//找到dom.allow_scripts_to_close_windows这项并改为true
var IsIE = (navigator.appName == 'Microsoft Internet Explorer')
if(IsIE){//如果是IE
window.opener.opener=null;
window.opener.close();
window.close();
}else{
alert("火狐不能直接关闭;需要以下设置1.开firefox,在地址栏输入about:config;2.找到dom.allow_scripts_to_close_windows这项并改为true");
}
}
取值:
alert(window.opener.document.getElementById("OpenDiv").innerHTML);
赋值:
window.opener.document.getElementById("OpenDiv").innerHTML="我是从子窗口Open传过来的值";
三、模态窗口篇
1.父窗口操作子窗口
父窗口JS代码:
var parValue="现在显示了父窗口中的变量值";
var hao="郝建卫";
function ShowDailog(PageHref,Title,Height,Width)
{
//--------------left位置
//screen.availHeight声明了显示浏览器的屏幕的可用宽度
var dleft =(screen.availHeight-Height)/2;
//--------------top位置
var dtop =(screen.availWidth-Width)/2;
//---------------
Var sRet = window.showModalDialog(PageHref,window,Title,"scrollbars=yes;resizable=no;help=no;status=no;center=yes;dialogTop=25;dialogLeft="+ dleft +";dialogTop="+ dtop +";dialogHeight="+Height+"px;dialogWidth="+Width+"px;");
//--------return
if (sRet =="refresh")//这种是利用返回值来刷新父页面
{
window.Test="true";
window.location.reload();
alert(window.Test);
}
}
function test()
{
alert("模态窗口成功调用父窗口的方法");
}
2.模态窗口操作父窗口
var parentWin=window.dialogArguments;
刷新:
parentWin.location.reload();
取值:
alert(parentWin.document.getElementById("ShowModalDialogDiv").innerHTML) //获取父窗口中的对象
alert("我是从父窗口中得到的变量>>>"+parentWin.parValue); //获取父窗口中的变量
调用父窗口JS方法:
parentWin.test(); //调用父窗口中的方法
赋值:
parentWin.document.getElementById("ShowModalDialogDiv").innerHTML="我是从子窗口ShowModalDialog传过来的值";
关闭本窗口:
//关闭本窗口
function CloseWindow()
{
window.parent.close();
}
关闭父窗口:
//关闭父窗口
function CloseModal()
{
var IsIE = (navigator.appName == 'Microsoft Internet Explorer')
if(IsIE){//如果是IE
window.parent.parent.close();
//parentWin.opener=null;如果把上面的换成这行,不能关闭父窗口,
parentWin.close();
//window.parent.parent.parent.parent.close();这个只能关闭模态窗口本身目前只在IE6下测试
}else{
alert("火狐不能直接关闭;需要以下设置1.开firefox,在地址栏输入about:config;2.找到dom.allow_scripts_to_close_windows这项并改为true");
}
}
分享到:
相关推荐
子窗口对父窗口的操作.rar子窗口对父窗口的操作.rar子窗口对父窗口的操作.rar子窗口对父窗口的操作.rar子窗口对父窗口的操作.rar子窗口对父窗口的操作.rar
HTML中IFrame父窗口与子窗口相互操作
C#中父窗口和子窗口之间实现控件互操作C#中父窗口和子窗口之间实现控件互操作
子父窗体操作 子父窗体操作 子父窗体操作 子父窗体操作
2> 父窗口与子窗口传递值的方式也有所不同,在子窗口中操作父窗口也语法也不同,分别为var parentObjs = window.dialogArguments;opener.parentObj.elementObj.arrtr = 'str'; 3> IE与FireFox对两个弹出窗口在...
在子窗口通过js操作父窗口中的元素,涉及js、html、dom
博文链接:https://hongan.iteye.com/blog/245498
自己写的代码,其中运用了Ajax查询数据,生成table,以及操作子窗口后,父窗口的刷新的三种方法
jquery 子窗口操作父窗口的实现代码。
1、不能使用window.parent Window.parent是用来在frame中进行操作的,在对话框中不能用来操作父窗口对象 2、正确的做法 调用modaldialog时通过传参数的方式操作 例: 需求 父窗口页面为a.html 子窗口页面为b.html。...
$(“#父窗口元素ID”,window.parent.document); 对应javascript版本为window.parent.document.getElementByIdx_x(“父窗口元素ID”); 取父窗口的元素方法:$(selector, window.parent.document);那么你取父窗口的...
子父窗口的操作 [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
主要介绍了js实现ifram取父窗口URL地址的方法,是javascript操作window.parent对象非常典型的应用技巧,需要的朋友可以参考下
主要介绍了C#中父窗口和子窗口之间控件互操作的方法,实例分析了父窗口与子窗口互操作的技巧,需要的朋友可以参考下
实现C#窗体间的调用,具体为父窗体按钮弹出子窗体,最重要的是实现了子窗体控件控制父窗体和其控件的功能,不同于以往的单单是父窗体操作子窗体,关键是本实例实现了子窗体操作父窗体的功能,是一种互操作!
在做一个联系人管理的C#设计时,遇到了这个问题,我需要将父窗体中的textBox中的值传到子窗体并进行数据库查询操作,我用了new 父窗体().textBox.text;来进行值传递,然而并无卵用,经过多次试验,找到了一个比较...
模态子窗体可以调用父窗体的任何函数方法,相当于在一个界面操作一样,超强的,顶!