一、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(); 取值:
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");
}
}

转载于http://www.cnblogs.com/haojianwei/archive/2010/03/02/1676707.html

JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作的更多相关文章

  1. 总结JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作

    一.Iframe 篇 //&&&&&&&&&&&&&&&&&&a ...

  2. 总结js(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作

    http://hi.baidu.com/yashua839/blog/item/131fdb2fe547ef221f3089af.html一.Iframe 篇 //&&&&am ...

  3. HTML中IFrame父窗口与子窗口相互操作

    一.Iframe篇 //&&&&&&&&&&&&&&&&&&am ...

  4. js window.open() 父窗口与子窗口的互相调用(未必有用)

    javascript 父窗口与子窗口的互相调用 <html> <head></head> <body> 主要实现父子关系的页面 window.opene ...

  5. #js window.open() 父窗口与子窗口的互相调用【转】

    未完整版 javascript 父窗口与子窗口的互相调用 a.html 父页面 <HTML> <HEAD> <meta http-equiv="content- ...

  6. iframe父窗口和子窗口之间的调用

    1>父窗口获取子窗口 js方法 document.getElementById('if1').contentWindow.document: window.frames["if1&qu ...

  7. iframe父窗口和子窗口的调用方法

    iframe 父窗口和子窗口的调用方法父窗口调用子窗口 iframe_name.iframe_document_object.object_attribute = attribute_value 例子 ...

  8. Iframe父页面与子页面之间的相互调用

    iframe元素就是文档中的文档. window对象: 浏览器会在其打开一个HTML文档时创建一个对应的window对象.但是,如果一个文档定义了一个或者多个框架(即:包含一个或者多个frame或者i ...

  9. Iframe父页面与子页面之间的调用

    原文:Iframe父页面与子页面之间的调用 Iframe父页面与子页面之间的调用 专业词语解释如下:     Iframe:iframe元素是文档中的文档.     window对象: 浏览器会在其打 ...

随机推荐

  1. 转换primitive主数据类型

    /*转换primitive主数据类型 * 短变长直接转换 * 长变短要强制转换 * 例如:long y = 42; int x = (int)y * String类型转换成primitive类型时可以 ...

  2. 用CSS定义每段首行缩进2个字符 转

    应该遵循w3c所制定的html/xhtml标准来使用tag和编写网页.如果你对此不太了解,可以到w3c的网站www.w3.org去找相关资料,或者买一本xhtml的书(注意不要买过时的html的书,尽 ...

  3. Android常见控件— — —EditText

    <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" ...

  4. gcc学习笔记

    1:第一个程序 : hello world #include <stdio.h> int main(void) { printf("Hello , world ! \n" ...

  5. 来自HeroKu的HTTP API 设计指南(中文版)

    原文转自:http://get.jobdeer.com/343.get 来自HeroKu的HTTP API 设计指南(中文版) 翻译 by @Easy 简介 本指南中文翻译者为 @Easy ,他是国内 ...

  6. (实用篇)PHP中单引号与双引号的区别分析

    在PHP中,我们可以使用单引号或者双引号来表示字符串.不过我们作为开发者,应该了解其中的区别.单引号与双引号对于定义字符一个是可以解析变量一个是会把变量直接输出来,同时单引号与双引号在字符处理上单引号 ...

  7. java.util.NoSuchElementException解决办法

    报错代码 public void switchToNewWindow(){ //得到当前句柄 String currentWindow = driver.getWindowHandle(); //得到 ...

  8. Thrift 个人实战--Thrift RPC服务框架日志的优化

    前言: Thrift作为Facebook开源的RPC框架, 通过IDL中间语言, 并借助代码生成引擎生成各种主流语言的rpc框架服务端/客户端代码. 不过Thrift的实现, 简单使用离实际生产环境还 ...

  9. redis windows

    下载 redis windows版本 redis-server  redis.windows.conf  //cmd 命令 启动成功 E:\redis\Redis-x64-3.0.500>red ...

  10. 如何在一个网站或者一个页面规划JS

    规划主要分为两部分:1.JS的分层,2.Js的规划 1.JS的分层(功能) 1-1.底层的库 : jquery  1-2.组件(ui) : 比如拖拽等,模块之间没有必然的联系,可以重复利用  1-3. ...