`
guoyiqi
  • 浏览: 964261 次
社区版块
存档分类
最新评论

location.hash实现跨域iframe自适应(转自:http://hi.baidu.com/leolance/blog/item/2ec6f3ee5a7152c3d439c923.html)

 
阅读更多

页面域关系:

主页面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.html,由于b.html的宽度和高度是不可预知而且会变化的,所以需要a.html中的iframe自适应大小.

问题本质:

js对跨域iframe访问问题,因为要控制a.html中iframe的高度和宽度就必须首先读取得到b.html的大小,A、B不属于同一个域,浏览器为了安全性考虑,使js跨域访问受限,读取不到b.html的高度和宽度.

解决方案:

引入代理代理页面c.html与a.html所属相同域A,c.html是A域下提供好的中间代理页面,假设c.html的地址:www.taobao.com/c.html,它负责读取location.hash里面的width和height的值,然后设置与它同域下的a.html中的iframe的宽度和高度.

代码如下:

a.html代码

b.html代码

c.html代码


其他一些类似js跨域操作问题也可以按这个思路去解决

分享到:
评论

相关推荐

    利用location.hash实现跨域iframe自适应

    www.baidu.com,假设地址:http://www.baidu.com/b.html 实现效果: A域名下的页面a.html中通过iframe嵌入B域名下的页面b.html,由于b.html的宽度和高度是不可预知而且会变化的,所以需要a.html中的iframe自适应大小....

    JMeterPlugins.jar

    path : /jmeterTestPlan/hashTree/hashTree/kg.apc.jmeter.vizualizers.CorrectedResultCollector line number : 2014 这样的情况下应该怎么办呢? 缺少了一个Jar 包,需要下载一个JAR包导进来就可以了。 /lib/ext =...

    window.location.hash解析

    NULL 博文链接:https://hugang357.iteye.com/blog/1833003

    根据输入邮箱号跳转到相应登录地址的解决方法

    话不多说,跟着小编一起来看下具体的实现代码吧 [removed] var hash={ 'qq.com':'http://mail.qq.com', 'gmail.com': 'http://mail.google.com', 'sina.com': 'http://mail.sina.com.cn', '163.com': '...

    Hash V1.04

    软件名称:Hash 软件版本:v1.04 软件类型:加密解密/免费软件 官方主页:http://keir.net 我的网站:http://Nigel.Ik8.Com 我的博客:http://Blog.Ik8.Com/Nigel 适用系统:Windows 9x/NT/2000/XP/2003 功能...

    hashcat [hashcat wiki].rar

    hashcat is the world’s fastest and most advanced password recovery tool. This version combines the previous CPU-based hashcat (now called hashcat-legacy) and GPU-based oclHashcat. Hashcat is ...

    hashcat-5.1.0.rar

    This version combines the previous CPU-based hashcat (now called hashcat-legacy) and GPU-based oclHashcat. Hashcat is released as open source software under the MIT license. Current Version ...

    基于微步HFish的fireeyeex蜜罐(fireeye火眼系列)

    基于微步HFish的fireeyeex蜜罐...1.避免因红队匹配hash导致内置蜜罐暴露而使用自定义蜜罐 2.使用自定义蜜罐,增加防守可靠性 3.多元多选择的企业级中低交互蜜罐 4.适用于防守方/攻防演练/日常防守 蜜罐定制可私信博主。

    jQuery微信手机端底部弹出导航菜单列表代码.zip

    if(ret.hasHref){ return }else{ // switch (ret.index){ // case 0: // alert(0); // break; // } alert(JSON.stringify(ret)); } } }); } function showList1(){ $("body")....

    小发现之浅谈location.search与location.hash的问题

    下面小编就为大家带来一篇小发现之浅谈location.search与location.hash的问题。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

    ethminer-0.16.0.dev3

    For Maxwell 2 GPUs: There is a way of mining ETH at Win7/8/Linux speeds on Win10, by downgrading the GPU driver to a Win7 one (350.12 recommended) and using a build that was created using CUDA 6.5. ...

    mimikatzWIN服务器神器

    http://blog.gentilkiwi.com/mimikatz http://pentestmonkey.net/blog/mimikatz-tool-to-recover-cleartext-passwords-from-lsass 用于调试程序 使用方法: 1. 运行主程序:mimikatz.exe 2. 输入:privilege::debug...

    com.google.android.webview_79.0.3945.93-394509365_minAPI21(x86)(nodpi).apk

    安卓内置的浏览器内核,适用于x86构架,如:华硕ze551ml....,最低系统要求安卓5.0.........................................................................................................................

    有序HASH内存表 win32 SDK V2.0

    内存表数据结构是指在内存中建立类似传统关系数据库管理系统(ORCALE、MS SQL SERVER)建立的...http://hi.csdn.net/link.php?url=http://blog.csdn.net%2Ffreeland008 本附加包括:动态库、头文件、用户文档、demo。

    General Purpose Hash Function Algorithms Library

    (* General Purpose Hash Function Algorithms Library *) (* *) (* Author: Arash Partow - 2002 *) (* URL: http://www.partow.net *) (* URL: ...

    Android_SDK离线开发环境 http://huakai.org

    文件中为百度网盘下载地址 谷歌经常被墙,有的同学也不知道如何下载平台环境,所以特意把全平台工具环境打包上来,方便大家下载。 此次更新日期为16年8月8日,包括谷歌最新更新的api24,文件使用分卷压缩,下载两个...

    shiro-crypto-hash-1.4.0-API文档-中文版.zip

    赠送jar包:shiro-crypto-hash-1.4.0.jar; 赠送原API文档:shiro-crypto-hash-1.4.0-javadoc.jar; 赠送源代码:shiro-crypto-hash-1.4.0-sources.jar; 赠送Maven依赖信息文件:shiro-crypto-hash-1.4.0.pom; ...

    微信服务商分账功能开发(PHP).docx

    要改一下SDK文件 在Data的签名里面必须使用HMAC-SHA256 ... $string = hash_hmac("sha256",$string,WxPayConfig::KEY); //签名步骤四:所有字符转为大写 $result = strtoupper($string); return $result; }

Global site tag (gtag.js) - Google Analytics