一、Iframe篇

//&&&&&&&&&&&&&&&&&&&&公共方法开始&&&&&&&&&&&&&&&

//父对象得到子窗口的值

//ObjectID是窗口标识,ContentID是元素ID

function GetValue(ObjectID,ContentID)

{

varIsIE = (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 == 'MicrosoftInternet 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

varIsIE = (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代码:

varparValue="现在显示了父窗口中的变量值";

varhao="郝建卫";

functionShowDailog(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.模态窗口操作父窗口

varparentWin=window.dialogArguments;

刷新:

parentWin.location.reload();

取值:

alert(parentWin.document.getElementById("ShowModalDialogDiv").innerHTML)   //获取父窗口中的对象

alert("我是从父窗口中得到的变量>>>"+parentWin.parValue);       //获取父窗口中的变量

调用父窗口JS方法:

parentWin.test();   //调用父窗口中的方法

赋值:

parentWin.document.getElementById("ShowModalDialogDiv").innerHTML="我是从子窗口ShowModalDialog传过来的值";

 

关闭本窗口:

//关闭本窗口

functionCloseWindow()

{

window.parent.close();

}

关闭父窗口:

//关闭父窗口

functionCloseModal()

{

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");

}

}

HTML中IFrame父窗口与子窗口相互操作的更多相关文章

  1. jquery操作iframe的方法:父页面和子页面相互操作的方法

    今天在弄jquery操作iframe中元素:先由iframe中的子页面b.html给外面的父页面a.html页面传值,再将a.html页面计算机的值放到b.html页面上,这里就用到子页面和父页面相互 ...

  2. iframe父页面和子页面相互调用的方法

    随着W3C一声令下,几年前使用非常频繁的frameset + frame已完成使命,光荣退伍.作为frameset的替代方案(姑且这么称吧),iframe的使用也多了起来.较frameset方案,if ...

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

    一.Iframe 篇 公共部分 //父对象得到子窗口的值 //ObjectID是窗口标识,ContentID是元素ID function GetValue(ObjectID,ContentID) { ...

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. ThinkPHP 3.2.3 简单后台模块开发(二)RBAC

    RBAC(Role-Based Access Controll)基于角色的访问控制 在 ThinkPHP3.2.3 中 RBAC 类位于 /ThinkPHP/Library/Org/Util/Rbac ...

  2. [转]SQLSERVER如何获取一个数据库中的所有表的名称、一个表中所有字段的名称

    1.查询数据库中的所有数据库名: SELECT Name FROM Master..SysDatabases ORDER BY Name 2.查询某个数据库中所有的表名: SELECT Name FR ...

  3. NSMutableAttributedString可变属性字符串的用法

    适用于:当你想对一个字符串中的某几个字符更改颜色,字体... NSString *string = @"今日营养配餐提供热量1800千卡,需要饮食之外额外补充钙10mg,铁20mg,锌9.5 ...

  4. windows的Timer和写文件方式串口注意!

    1.Timer要读取并分发消息,才能触发自定义回调函数 SetTimer(NULL, 1, 40, (TIMERPROC)TimerProc); while(GetMessage(&msg, ...

  5. ASP.NET MVC中,怎么使用jquery/ajaxForm上传文件

    ajaxForm插件最好选择:jquery forms plugin. 以下为示例: Ajax.BeginForm @using (Ajax.BeginForm("YourAction&qu ...

  6. linux的命令

    Linux命令的分类 选项及参数的含义 以"-"引导短格式选项的(单个字符),例如"-l" 以"--"引导长格式选项(多个字符),例如&qu ...

  7. scrum3.0

    3.0----------------------------------------------------- SCRUM 流程的步骤2: Spring 计划 1. 确保product backlo ...

  8. struts2实现文件上传、多文件上传和文件下载

    总结的两个问题,就是struts2上传下载的时候对属性名配置要求非常严格: 第一:上传的时候 private File file; private String fileContentType; pr ...

  9. 配置MyBatis

    创建WebProject之后先把mybatis-3.2.2.zip里的mybatis-3.2.2.jar包和lib里的asm-3.3.1.jar.cglib-2.2.2.jar.commons-log ...

  10. java 笔试题 字符串旋转

    package com.shb.java; /** * 取出第一个重复的字符 * @author shaobn * @date 2016-9-28 * @package_name com.shb.ja ...