`
uule
  • 浏览: 6309253 次
  • 性别: Icon_minigender_1
  • 来自: 一片神奇的土地
社区版块
存档分类
最新评论

iframe总结 + window.open

阅读更多

从frame中跳出并转向:

parent.window.location.href = "<%=basePath%>package.do";

或top.window.location.href = "<%=basePath%>package.do";

 

 

<iframe name="myFrame" src="child.html"></iframe>

1、方法调用:

父窗口调用子窗口:myFrame.window.functionName();
子窗品调用父窗口:parent.functionName();

2、属性调用:
1、IE中使用方法:
父窗口调用子窗口:iframe_ID.iframe_document_object.object_attribute = attribute_value
例子:onClick="iframe_text.myH1.innerText='http://www.pint.com';"
子窗口调用父窗口:parent.parent_document_object.object_attribute = attribute_value
例子:onclick="parent.myH1.innerText='http://www.pint.com';"

2、Firefox中使用方法:
上面在IE下没有问题,但在firefox下不正常。在firefox下,应该是如下调用方法:
父窗口调用子窗口:window.frames["iframe_ID"].document.getElementById("iframe_document_object"­).object_attribute = attribute_value
例: window.frames["iframe_text"].document.getElementById("myH1").innerHTML= "http://hi.wonsoft.cn ";
子窗口调用父窗口:parent.document.getElementById("parent_document_object").object_attribute = attribute_value
例: parent.document.getElementById("myH1").innerHTML = "http://wonsoft.cn ";

参考:http://keyknight.blog.163.com/blog/static/36637840200973101612654/

 

点击前页面:


分别点击后页面:



 

父窗口iframe.jsp:

<script>
  	function say() {
   		alert("I'm at parent.html");
   	} 

	function callChild()
	{      		
   		ifr.window.say();    //调用iframe中say方法
   		
   		//修改iframe中属性值
   		ifr.myH2.innerHTML = "Child H1 changed!";  //IE
   		//ifr.document.getElementById("myH2").innerHTML = "Child H1 changed!"; //IE下两种方法都可以
   		
   		//window.frames["ifr"].document.getElementById("myH2").innerHTML = "Child H1 changed in FireFox!" ; //FireFox
	}	    
</script>
  <body>
  	Parent:
  	<h1 id="myH1">Parent H1</h1> 
  	<input   type=button   value="调用child.html中的函数say()" onclick="callChild()"/>  
    <iframe id="ifr" name="ifr" src="child.jsp" scrolling="auto"></iframe>    
  </body>

 子窗口child.jsp:

<script type="text/javascript">      
	function say()   
	{   
        alert("I'm at child.html");   
	} 

	function callParent() {
   		parent.say();    //调用父窗口say方法
   		parent.myH1.innerHTML = "Parent H1 Changed!"; //IE
   		//parent.document.getElementById("myH1").innerHTML = "Parent H1 changed in FireFox!" ; //FireFox
   	} 
</script>    
  </head>
  
  <body>
    This is my JSP page. <br>
    <h1 id="myH2">Child H1</h1> 
    <input   type=button   value="调用parent.html中的say()函数"   onclick="callParent()">    
  </body>

 

自适应高度:

function iFrameHeight() { 		 
		//var subWeb = document.frames ? document.frames["ifr"].document : ifm.contentDocument;   
		var subWeb = document.frames ? document.frames["ifr"].document : ifm.contentWindow.document;   
		
		var ifm= document.getElementById("ifr");  
		if(ifm != null && subWeb != null) {
			//alert(subWeb.body.scrollHeight);
		   setTimeout(function(){ifm.height = subWeb.body.scrollHeight;},1000);
		   //需要使用延迟方法,否则第一次时不会自动适应高度
		   //不用延迟方法用alert()也可以 ,但一般不需要alert		   
		}   
	}

 。。。

 

Window.open:


window.open("<%=basePath %>fareHeaders.do","upload","menubar=no,status=no,resizable=no,scrollbars=1,width=600,height=200pt,top=200,left=300");

 

打开的页面:

var parentWin = window.dialogArguments?window.dialogArguments : window.opener;
window.onload = function(){
        var mm = "${MESSAGE}";
        if(null != mm && mm == "Save Ok!"){
            var line = $("fareHeadersBean.marketingAirline").value;
            var refId = $("fareHeadersBean.refId").value;
            var dis = $("fareHeadersBean.distributor").value;
            parentWin.doaddrefId(line,refId,dis);     //调用父页面方法doaddrefId
            window.close(); 
        }
    }

 
子页面点击Save后,request.setAttribute(MyConstants.MESSAGE_KEY, "Save Ok!");再进入子页面后,mm不为空,可传值给父页面。

 

模态窗口:

var returnValue = window.showModalDialog('<%=basePath%>package/fareLevel.jsp',"fareLevel","status:false;dialogWidth:350px;dialogHeight:150px");

 

子页面:

<html>
	<head>
		<base href="<%=basePath%>">
		<title>Fare level</title>
		<script type="text/javascript">
		function doConfirm(){
			var fareLevel = document.getElementById("fareLevel");
			if(fareLevel.value==""){
				alert(" Please input !");
				return false;
			}
			window.returnValue=fareLevel.value;
			window.close();
		}
		</script>

	</head>
	<body style="text-align: center;">
	<div >
		<br>Fare Level:<input type="text" id="fareLevel" />
		<br>
		 <br/>
		<input type="button" onclick="return doConfirm();" style="width: 60" value="OK">
		</div>
	</body>
</html>

 。。。

 

 

 

 

 

  • 大小: 20.9 KB
  • 大小: 24.2 KB
  • 大小: 25.7 KB
  • 大小: 58.8 KB
分享到:
评论
3 楼 我是你们的爹 2016-05-17  
这是多少年前的东西了还不删?问题这么多不是在误导别人么
2 楼 dkw19860421 2014-05-21  
360和谷歌不适用,刚才发错了
1 楼 dkw19860421 2014-05-21  
火狐和360不适用啊

相关推荐

    js window.open iframe dialog

    js window.open iframe dialog 例子

    HTML5如何用window.postMessage在网页间传递数据

    作为发起端,我们可以open一个新窗口,或创建一个iframe,往新窗口里发送数据,简单起见,我们每6秒钟发送一次,然后创建消息监听器,从目标窗口监听它反馈的信息。 //弹出一个新窗口 var domain = '...

    JS控制弹出页面窗口控件(openWin)

    window.open()和window.showModalDialog(),并解决了showModalDialog()弹出窗口中列表分页的问题。 提供了三个JS方法: (1)showWindow(sURL, width, height); (2)showWindowInPage(pageUrl, params, title, ...

    chrome-extension---Access-Local-Files:Chrome扩展程序可打开本地文件并执行跨域访问的iframe中的window.open

    从iframe打开window.open Chrome会阻止从跨域框架中单击的所有window.open。 该扩展名允许您打开窗口。 单击链接到本地​​文件。 文件打开。Chrome商店原始扩展名 原始的chrome扩展名仅允许打开本地链接。 我已经...

    详解js location.href和window.open的几种用法和区别

    一、location.href常见的几种形式 self.location.href;//当前页面打开URL页面 [removed].href;//当前页面打开URL页面 this.location.href;//当前页面打开URL页面 location.href;// 当前页面打开URL页面 ...

    layer.open关闭父窗口 以及调用父页面的方法

    实例如下: //调用父类方法 window.parent.exportData($('#shownum').val(),$('#splitstr').val())...以上这篇layer.open关闭父窗口 以及调用父页面的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希

    最全的jquery-easyui扩展

    1. 在datagrid中首列标示“序号”二字 ; 2. datagrid翻页,取消勾选当前页中的所有行; 3. 没有数据时datagrid中显示...7. 查找iframe和window.open()打开父window; 8. 查找iframe和window.open()打开最顶层window。

    window.parent与window.openner区别介绍

    今天总结一下js中几个对象的区别和用法: 首先来说说 parent.window与top.window的用法 “[removed].href”、”location.href”是本页面跳转 “parent.location.href”是上一层页面跳转 “top.location.href”是最...

    jsp 刷新父页面

    刷新一open()方法打开的窗口 window.opener.location.href = window.opener.location.href 刷新以winodw.showModelDialog()方法打开的窗口 window.parent.dialogArguments.document.execCommand('Refresh'); ...

    layer.open的自适应及居中及子页面标题的修改方法

    layer.open的自适应: var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引 parent.layer.iframeAuto(index); layer.open居中: var index1 = layer.load(2, { shade: false });//...

    layui 弹出层值回传解决方式

    如下所示: layer.open({ type: 2, title: "设置围栏", shadeClose: true, shade: 0.4, area: ['90%', '90%'], content: "/ElectronicFence/Map?... var res = window["layui-layer-iframe" +

    JS window对象的top、parent、opener含义介绍

    2.openeropener用于在window.open的页面引用执行该window.open方法的的页面的对象。例如:A页面通过window.open()方法弹出了B页面,在B页面中就可以通过opener来引用A页面,这样就可以通过这个对象来对A页面进行...

    jquery插件jbox使用iframe关闭问题

    此按钮调用close方法关闭,弹出窗口,没有办法关闭,因为close方法需要以个参数,参数应该是那个iframe但是将其传入并不生效,不知道为什么在网上查找也没有找到解决方案。。 最后只好自己改其源码,在其close方法第...

    layui弹出层按钮提交iframe表单的方法

    如下所示: layer.open({ id: 'LAY_layuipro', //设定一个id,防止重复弹出 ... var inputForm = $(window.frames[layui-layer-iframe + index].document).contents().find(#userForm); inputForm.

    一个简单的网页框架 frame

    window.open('index.html','','toolbar=no,menubar=no,location=no,status=no,width=' + screen.width + ',height=' + screen.height + ',left=0,top=0'); } &lt;meta name= "robots " content= "noindex "&gt; ...

    新浪网易的评论块制作源码

    新浪网易的评论块制作源码 ... var newwindow = window.open("tab.htm",'_blank', toolbars=0,resizable=1); 5. iframe里执行父窗体的方法 window.opener.XXX(xxx); 运行项目执行 HTMLPage2.htm 页面,进行测试吧

    layer 刷新某个页面的实现方法

    一:使用layer.open打开的子页面 window.parent.location.reload()//刷新父页面 var index = parent.layer.getFrameIndex(window.name)//获取窗口索引 ...$(window.parent.document).find("iframe")[0].contentWin

    Javascript框架,弹出新的窗口,警告框

    Javascript,iframe的使用,框架,弹出新的窗口,警告框 window.open Javascript,iframe的使用,框架,弹出新的窗口,警告框 window.open Javascript,iframe的使用,框架,弹出新的窗口,警告框 window.open ...

    JS父页面与子页面相互传值方法

    主要介绍了使用JS在父页面和子页面间相互传值方法,子页面可以是window.open弹出的,也可以是iframe框架中的页面,需要的朋友可以参考下

    zDialog弹出框-内附使用说明及demo

    代替window.open、window.alert、window.confirm;提供良好的用户体验; 水晶质感,设计细腻,外观漂亮; 兼容ie6/7/8、firefox2/3、Opera;弹出框在ie6下不会被select控件穿透; 无外部css文件,引用Dialog.js...

Global site tag (gtag.js) - Google Analytics