Extjs3.4 获取iframe中连接的子页面中的store 急急急!!!!

Extjs3.4 获取iframe中连接的子页面中的store 急急急!!!!,第1张

首先假设父子页面的html代码如下:

PageParenthtml

<html>

 <head>

  <title> 父页面 </title>

 </head>

 <body>

 <div id="divParent">我们在下面嵌入一个IFrame指向PageSonhtml:</div>

 <iframe id='IF_ID_NEED' src="PageSonhtml" width="300" height="200" scrolling="no" frameborder="1"></iframe>

 <div>

 <input type="button" value="Input" onclick="alert(documentgetElementById('IF_ID_NEED')contentWindowdivSonvalue);">

 <input type="button" value="Script" onclick="documentgetElementById('IF_ID_NEED')contentWindowsayHello('Script!');">

 </div>

 </body>

</html>

PageSonhtml

<html>

 <head>

  <title> 子页面 </title>

  <script type="text/javascript">

  function sayHello(name){

  alert('Hello '+name);

  }

 </script>

 </head>

 <body>

 这是子页面:

 <input id="divSon" value="子页面Input元素!"/>

 <input type="button" value="Access DIV" onclick="alert(windowparentdocumentgetElementById('divParent')innerHTML);">

 </body>

</html>

简单而言,就是:

从父页面访问子页面的DOM或者JavaScript

alert(documentgetElementById('IF_ID_NEED')contentWindowdivSonvalue);

documentgetElementById('IF_ID_NEED')contentWindowsayHello('Script!');

从子页面访问父页面DOM的情况

alert(windowparentdocumentgetElementById('divParent')innerHTML);

运行此示例可能会碰到same-origin policy即所谓同源禁止跨域问题,解决:

Firefox目前版本支持对file:协议实现同源访问

谷歌浏览器截至版本 280150095 m还不允许,不过可以加参数启动chromeexe --disable-web-security

当然示例如果运行在localhost或者127001的网页服务器模式下自然就没有跨域一说了

那么你的问题就显而易见了:

store: windowparentstore//该store怎样从ajsp页面中获取

要解释这个问题,首先要解释两个技术点。

每个“窗口”都是一个JS Runtime,即JS的运行时。如果只有一个窗口,那么就只有一个Runtime;如果一个窗口下面还有一个iframe,那么就有两个Runtime;以此类推。

Runtime之间互 *** 作(或者通信)是有跨域限制的。也就是说,如果这个窗口本身是abaiducom域名下的页面,那么如果这个页面下还有一个iframe,这个iframe中加载的页面是bbaiducom域名下的。那么外层的JS。就不能跟这个iframe中的内容互 *** 作(或者通信)。

因此外层Runtime中的JS想 *** 作内层iframe中的内容,就必须要避免跨域限制。要么内层iframe加载页面的域名跟外层是一样的。要么就是需要在内层iframe加载的页面中执行documentdomain = 'baiducom';从而设置跟外层的主域相同。

例如,当前页面是abaiducom/testhtml

<html>

<head>

</head>

<body>

<iframe id="iFrm1" src = "0c893329b8c9af6ff578db9b1a128d13"margin: 0px; padding: 0px; color: rgb(69, 69, 69); font-family: arial, 宋体, sans-serif, tahoma, 'Microsoft YaHei'; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0301961); -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">

iframe中加载的页面内容如下:

<html>

<head>

</head>

<body>

<div id="innerDiv">恭喜 *** 作到内部iframe中的元素了!!!</div>

<script>

documentdomain = 'baiducom';

</script>

</body>

</html>

在HTML5中新增了postMessage的API。可以方便窗口跟内部iframe之间进行通信,并且可以实现跨主域通信。但是有一些限制,1老版本的浏览器一般不支持。2父窗口只能向iframe中发送信息,iframe只能收消息,且父窗口不能直接 *** 作iframe中的内容。3父窗口发送的数据也是有限制的。只能发送基本数据类型或者plain object。

您好!很高兴为您答疑。

首先,您要保证您的访问是没有跨域的,因为新的安全机制,这种js代码在跨域情况下是无效的。然后,在父窗口中获取iframe中的元素,可参考:

格式:$("#iframe的ID")contents()find("#iframe中的控件ID");

实例:$("#ifm")contents()find("#btnOk");

以上代码获取到的都是实例对象,请注意。

如果对我们的回答存在任何疑问,欢迎继续问询。

documentgetElementById(Iframe_Id)contentDocumentgetElementById(Element_Id) //适用于IE7以上

documentgetElementById(Iframe_Id)contentWindowdocumentgetElementById(Element_Id) //适用于IE6及火狐

参考 : >

在iframe子页面获取父页面元素 代码如下: 代码如下: $('#objld', parentdocument); 在父页面获取iframe子页面的元素 代码如下: 代码如下: $("#objid", documentiframes('iframe')document) 或 代码如下: $(documentgetElementById('ifram

1、父页面中的iframe

复制代码 代码如下:

<iframe name="parentPage"></iframe>

2、子页面中元素的属性

复制代码 代码如下:

<input type="text" id="date" data-dojo-type="dijit/form/DateTextBox" value="2013-11-12"/>

3、取子页面中DateTextBox中值

复制代码 代码如下:

var statisDate = windowframes["parentPage"]documentgetElementById('date')value;

$(function(){

    $("#rigth")load(function(){

        consolelog($(this)contents()find("#tableA")css('width'));

    });

});

你要等iframe加载完毕之后再去获取,否则你获取的是空的元素

以上就是关于Extjs3.4 获取iframe中连接的子页面中的store 急急急!!!!全部的内容,包括:Extjs3.4 获取iframe中连接的子页面中的store 急急急!!!!、JavaScript 怎么跨域获取 iframe 中的内容、火狐下无法获取iframe下的元素,请问各位如何解决等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9299130.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-26
下一篇2023-04-26

发表评论

登录后才能评论

评论列表(0条)

    保存