通过iframe hash 实现跨域

<h1>我是A页面</h1>
<iframe name="bpage" frameborder="0" scrolling="no" width="300" height="150" src="http://b.com/kuayu/b/b.html"></iframe>
<script type="text/javascript">
window.crossLoad = function() {
    window.location.reload();
};
window.setBackGroundColor = function(color) {
    if(color){document.body.style.backgroundColor = color};
};
</script>

 

 

测试页面
<div id="colordiv">
    <button action-type="setColor">red</button>
    <button action-type="setColor">green</button>
    <button action-type="setColor">yellow</button>
</div>

<iframe id="testframe" frameborder="0" scrolling="no" width="0" height="0" src="http://a.com/kuayu/a/delegate.html"></iframe>
<script src="http://127.0.0.1/STK/js/gaea_1_19.js"></script>
<script>

var node = STK.E("colordiv");
var testframe = STK.E("testframe");
var delegate = STK.delegatedEvent(node);
delegate.add("setColor" , 'click' , function(spec) {
    var color = spec.el.innerHTML;
    var obj = {
        funcName : "setBackGroundColor",
        args : [color]
    };
    testframe.src = testframe.src.replace(/#[^#]*$/ , "") + "#" + encodeURIComponent(STK.jsonToStr(obj));
});
</script>

 

<script>
window.location.hash = '';
var originHash;
function detectHash() {
    var nowHash = window.location.hash;
    if(nowHash && originHash != nowHash) {
        originHash = nowHash;
        var realHash = eval('(' + decodeURIComponent(nowHash.replace(/^#/ , '')) + ')');
        var funcName = realHash.funcName;
        var args = realHash.args;
        window.top[funcName].apply(window , args);
    }
};
setInterval(detectHash , 500);
</script>

iframe记录历史记录(onhashchange) NULL 博文链接:https://smiky.iteye.com/blog/1917700 立即下载

相关推荐

工具方法:js设置iframe的src为哈希路由(Hash模式)时地址改变页面也不刷新生效处理

## 工具方法:js设置iframe的src为哈希路由(Hash模式)时地址改变页面也不刷新生效处理 Hash路由模式替换地址页面也不更新,History模式正常 ## 处理方案: 在 # 前加随机数或时间戳即可 ## 示例方法: ```javascript onReset(item, index, e) { e.stopPropagation(); const getIframe = document.querySelectorAll('.inner-iframe')[inde

刻痕 1025

利用iframe和location.hash实现

原理是利用location.hash来进行传值。在url: http://a.com#helloword中的‘#helloworld’就是location.hash,改变hash并不会导致页面刷新,所以可以利用hash值来进行数据传递,当然数据容量是有限的。假设名a.com下的文件cs1.html要和cnblogs.com名下的cs2.html传递信息,cs1.html首先创建自动创建一个隐藏

铭霏的记事本 7843

iframe 使用心得

本文全面介绍了HTML中的<iframe>元素,包括其工作原理、基本语法、源通信、使用场景、安全性考量和性能优化。<iframe>允许在当前页面内嵌入外部资源,通过隔离环境实现页面展示。文章详细讲解了postMessage实现源通信的方法,并列举了嵌入视频/地图、支付页面等典型应用场景。在安全方面,建议使用sandbox属性、X-Frame-Options和CSP策略进行防护。性能优化部分提出了延迟加载、srcdoc内联内容、重用iframe等技巧。最后总结了限制权限、避免过度

青蛙king的博客 635

iframe _常见解决方案(一)

什么是是指一个下的文档或脚本试图去请求另一个下的资源,这里是广义的。广义的:1)资源跳转:A链接、重定向、表单提交2)资源嵌入:、 服务端返回如下(返回时即执行全局函数):handleCallback({"status": true, "user": "admin"})2、jquery ajax$.ajax({ url: 'http://www.tunan...

weixin_39533795的博客 6947

前端路由之hash,以及iframe页面直接传参

//通过hash值路由页面                        //处理页面刷新时的状态                         localStorage.hash = location.hash;                         if(localStorage.hash) {                                 $("a").

qq_15980201的博客 1395

location.hash实现iframe自适应

location.hash实现iframe自适应 作者:heiniu 时间: 2009-08-05 文档类型:合作网站提供 来自:阿里妈妈UED  页面关系: 主页面a.html所属A:www.taobao.com 被iframe的页面b.html所属B:www.ali

阿义的专栏 826

通过 iframe 和 location.hash 进行通信

javascript 中 location.hash 是指   www.aa.com/a.php#abc 中的#abc。 在本试验中,在局网中用两台Windows 机器分别搭建了PHP的简单系统。通过设置 hosts 文件,使得A机器的系统网址为www.sso.com/SSO     B机器系统网址为www.javascript.com/SSO  本实验模拟的是 A 中通过IFrame将 B

veverrr的专栏 4325

javascript通信(一):利用location.hash实现iframe自适应

页面关系:a.html所属A:www.A.comb.html所属B:www.B.com 问题本质: js对iframe访问问题,因为要控制a.html中iframe的高度和宽度就必须首先读取得到b.html的大小,A、B不属于同一个,浏览器为了安全性考虑,使js访问受限,读取不到b.html的高度和宽度. 解决方案: 引入代理代理页面c.html与a.html所属相同A...

weixin_30585437的博客 129

[转]利用location.hash实现iframe自适应高宽

觉得写得不错,以前工作的时候也想过做frame的自适应高度的,可惜没做成。现在终于学到了。 页面关系: 主页面a.html所属A:www.taobao.com 被iframe的页面b.html所属B:www.alimama.com,假设地址:http://www.alimama.com/b.html 实现效果: A名下的页面a.html中通过iframe嵌入B名下的页面b....

iteye_20293的博客 147

利用location.hash实现iframe自适应高宽

转载:http://ued.alimama.com/front-end/use-location-hash-to-auto-sizing/ 页面关系: 主页面a.html所属A:www.taobao.com 被iframe的页面b.html所属B:www.alimama.com,假设地址:http://www.alimama.com/b.html 实现效果: A名下的页面a.ht

香巴拉 628

iframe的使用,同问题

看了一些博客,进行了总结和实践 iframe的使用 <iframe src="demo.html" height="300" width="500" name="demo" scrolling="auto" sandbox="allow-same-origin"></iframe> src iframe页面地址,有同之分 name iframe命名,可通过window.frames[xxx]被调用 iframe框架中的页面与主页面之间的通信方式根据iframe中src属性

stormeye_的博客 7375

location.hash + iframe

实现原理: a欲与b相互通信,通过中间页c来实现。 三个页面,不同之间利用iframe的location.hash传值,相同之间直接js访问来通信。 具体实现: A:a.html -> B:b.html -> A:c.html,a与b不同只能通过hash值单向通信,b与c也不同也只能单向通信,但c与a同,所以c可通过parent.parent...

u011089760的博客 862

前端处理的九种方式(超级详细)

指一个下文档或者脚本去请求另一个下的资源,这里的是广义的;同源策略(Same origin policy),简称SOP,是一种约定,它由Netscape公司1995年引入浏览器,它是浏览器核心也是最基本的安全功能,如果缺少同源策略,浏览器很容易受到XSS、CSFR等攻击。所谓同源是指“协议+ 名+ 端口”三种相同;

贫僧法号依平 2万+
上一篇: js ajax 函数
下一篇: 全角半角字符
java_mail_test
博客等级 码龄17年 1粉丝 299原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值