为了轻松偷懒,不想从目的项目中开发目标项目中的页面,但目的项目中需要获取老项目中的页面,这里用了iframe跨域链接页面出现了问题

Blocked a frame with origin "http://......" from accessing a cross-origin frame.

出现此报错的原因是因为在http://driversys.edaijia.cc 下操作 http://www.edaijia.cc   下的dom导致。

项目框架是yii2,代码如下,项目中是在看代码中http://driversys.edaijia.cc 下操作的iframe连接指向是http://www.edaijia.cc   dom元素。

//http://driversys.edaijia.cc 项目下代码
<?php
Modal::begin([
'id' => 'create-modal-article',
'header' => '<h4 class="modal-title">选择长文章</h4>',
'footer' => '<a href="javascript:;" class="btn btn-info" id="confirm_article" >确定</a><a href="javascript:;" class="btn btn-danger" id="close_article_window" >关闭</a>',
]);
$requestUrl = 'http://www.edaijia.cc/v2/index.php?r=newNoticePost/selection';
$js = <<<JS
$('#create-modal-article .modal-body').html('<iframe name="article_ifm" id="add_long_article" width="99%" height="100%" style="border:0px"></iframe>');
$("#add_long_article").attr("src", 'http://www.edaijia.cc/v2/index.php?r=newNoticePost/selection'); $('#create-modal-article').find('.modal-header').find('.close').hide();
JS;

解决方法:

在父页面添加监听器,接收子页面的值:

window.addEventListener('message',function(e){

alert(e.data);

},false);

在子页面在要传值的地方调用以下语句传值:

window.parent.postMessage('值','http://www.....);

解决代码:

//http://www.edaijia.cc项目代码 

$("#new-notice-post-grid :radio").on('click', function () { //监听radio选中,并把值传递
window.parent.postMessage([$(this).attr('did'),$(this).val()],'http://driversys.edaijia.cc');
})
//http://driversys.edaijia.cc  项目代码,获取传递的值
//长文章radio获取
window.addEventListener('message',function(e){
window.did = e.data[];
window.title = e.data[]; },false);

跨域问题 Blocked a frame with origin "http://......" from accessing a cross-origin frame.的更多相关文章

  1. java、ajax 跨域请求解决方案('Access-Control-Allow-Origin' header is present on the requested resource. Origin '请求源' is therefore not allowed access.)

      1.情景展示 ajax调取java服务器请求报错 报错信息如下: 'Access-Control-Allow-Origin' header is present on the requested ...

  2. 前后端分离 导致的 静态页面 加载 <script type="module" > 报CORS 跨域错误,提示 blocked by CORS policy

    1.前言 静态页面 加载 <script type="module" > 报CORS 跨域错误,提示Access to script at ftp:///xxx.js ...

  3. js如何获取跨域iframe 里面content

    每天学习一点点 编程PDF电子书.视频教程免费下载:http://www.shitanlife.com/code 其中src可能存在跨域. 现有的获取方式   var test = document. ...

  4. 跨域传输信息postMessage

    widnow.postMessage()方法允许安全的跨域传输. Syntax otherWindow.postMessage(message, targetOrigin, [transfer]); ...

  5. 前端Js跨域方法汇总—剪不断,理还乱,是跨域

    1.通过jsonp跨域2.通过修改document.domain来跨子域(iframe)3.隐藏的iframe+window.name跨域4.iframe+跨文档消息传递(XDM)5.跨域资源共享 C ...

  6. CP="CAO PSA OUR" 用P3P header解决iframe跨域访问cookie

    1.IE浏览器iframe跨域丢失Session问题 在开发中,我们经常会遇到使用Frame来工作,而且有时是为了跟其他网站集成,应用到多域的情况下,而Iframe是不能保存Session的因此,网上 ...

  7. 前端页面调用Spring boot接口发生的跨域问题

    最近要重构一个基于spring boot的后端API服务,需要再本地测试.在本地测试时,运行在本地的前端页面发送一个ajax请求访问后端API,然后浏览器报错blocked CORS policy. ...

  8. IE下IFrame引用跨域站点页面时,Session失效问题解决

    问题场景:在一个应用(集团门户)的某个page中, 通过IFrame的方式嵌入另一个应用(集团实时监管系统)的某个页面. 当两个应用的domain 不一样时, 在被嵌入的页面中Session失效.(s ...

  9. java springmvc 前端 跨域问题

    有个朋友在写扇贝插件的时候遇到了跨域问题.于是我对解决跨域问题的方式进行了一番探讨. 问题 API:查询单词URL: https://api.shanbay.com/bdc/search/?word= ...

随机推荐

  1. Srping MVC ant路径匹配

    背景 最近有一个功能设计path匹配,开发说支持ant匹配,这是我第一次听说这个词,赶紧补一下功课. Ant匹配规则 1.前言 (1)SpringMVC的路径匹配规则是按照Ant来的,实际上不只是Sp ...

  2. arcgis api for javascript 学习(五) 实现地图绘制工具

    1.本文实现的功能为鼠标与地图之间的交互,能够在地图上绘制不同形状的图形 2.代码部分主要讲到的为Graphic函数的相关功能 <!DOCTYPE html> <html> & ...

  3. 工具类ToastUtil 避免在子线程中使用抛异常 "Can't create handler inside thread that has not called Looper.prepare()"

    package com.example.kbr.utils; import android.view.Gravity; import android.widget.Toast; import io.r ...

  4. LayoutSubviews的调用

    1.当view被添加到另一个view上时调用 2.布局子控件时调用 3.屏幕旋转的时候调用 4.当view的尺寸大小改变的时候调用

  5. [b0032] python 归纳 (十七)_线程同步_信号量Semaphore

    代码: # -*- coding: utf-8 -*- """ 多线程并发同步 ,使用信号量threading.Semaphore 逻辑: 多个线程,对同一个共享变量 , ...

  6. HTML&CSS基础-子元素和后代元素选择器

    HTML&CSS基础-子元素和后代元素选择器 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.html源代码 <!DOCTYPE html> <html ...

  7. Tangent element-Vs虚拟调色台安装配置

    iPad安装element-Vs 从Tangent网站下载Element-Vs的Tangent Hub程序安装 确保系统防火墙允许对Tangent Hub的网络访问并且与iPad共用一个局域网连接 开 ...

  8. ACM-ICPC 2018 南京赛区网络预赛 I. Skr(回文树)

    题意 https://nanti.jisuanke.com/t/A1955 求所有本质不同的回文串转成数后的和. 思路 如果了解回文树的构造原理,那么这题就很简单了,回文树每个结点代表一个回文串,每添 ...

  9. RC4 对称加密

    public class RC4 { byte[] s = new byte[256]; byte[] key; byte keylen;// 4 ~ 16 int pi = 0; int pj = ...

  10. day2_窗口句柄切换

    #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2019/7/16 14:21 # @Author : 大坏男孩 # @File : d ...