iframe

Pure JavaScript function similar to jQuery.offset()?

随声附和 提交于 2020-01-21 04:54:51
问题 In a small iframe-application at the Russian social network Ok.ru I use the following call to resize the iframe: <div id="fb-root"></div> <script src="http://api.odnoklassniki.ru/js/fapi.js" type="text/javascript"></script> <script type="text/javascript"> FAPI.init("http://api.odnoklassniki.ru/", "XXX_YYY", function() { alert("clientHeight " + document.getElementById("fb-root").clientHeight); alert("offsetHeight " + document.getElementById("fb-root").offsetHeight); FAPI.UI.setWindowSize(720,

JS篇 同源策略、CORS、XSS、SessionCookie

女生的网名这么多〃 提交于 2020-01-21 03:27:07
同源策略: 如何引用: (iFrame指的是iframe DOM节点) 1. 引用iframe的window对象:iFrame.contentWindow 2. 引用iframe的document对象:iFrame.contentDocument,或者:iFrame.contentWindow.document 示例: 两个页面,前者页面中嵌入iframe,src指向后者: 1. test.nuomi.com/link1.vm 2. nuomi.com/link2.vm; 同源要求:Protocols, domains, and ports均相同 子域名不同的两个站:test.nuomi.com, nuomi.com,如果要通信, 都 必须设置为统一的域名:document.domain=nuomi.com; 即使其中一个已经是域名:nuomi.com,仍然需要 明确调用 :document.domain=nuomi.com; document.domain设值: 1. 只能是当前域名的suffix,否则报错:Uncaught SecurityError: Failed to set the 'domain' property on 'Document': 'test' is not a suffix of 'test.nuomi.com'. 2. 设值为com也会报错:'com'

iframe在iphone手机上的问题

ぃ、小莉子 提交于 2020-01-20 11:22:40
问题1: 通过document.addEventListener("scroll",function(){})对页面滚动监听事件进行监听,但ios下$(document).scrollTop()值始终为0,对页面监听无效。 原因: 因为iOS下iframe的高度会根据页面的内容自适应,造成了iframe的高度过高(即iframe的高度>屏幕的高度)。则iframe内部html、body标签即使设置为100%,它的值也是页面所有内容撑开的高度。 解决方法: 将body设置为fixed,宽高设为100%,添加-webkit-overflow-scrolling: touch;在body下写一个div,针对这个div进行scroll监听操作。 html{ position: relative; width: 100%; height: 100%; overflow: hidden; } body{ position: fixed; top: 0; left: 0; width: 100%; height: 100%; overflow: auto; -webkit-overflow-scrolling: touch; } 问题2:ios中点击,通过display=block或.show()显示元素会跳转顶部。 解决方法:将元素设置为visibility:hidden,通过改变值为

解决location.href=“xxxx”无法跳转的问题

不问归期 提交于 2020-01-20 04:29:41
首先总结 location.href=“xxxx” 的多种用法如下: self.location.href="/url" 当前页面打开URL页面 location.href="/url" 当前页面打开URL页面 windows.location.href="/url" 当前页面打开URL页面,前面三个用法相同。 this.location.href="/url" 当前页面打开URL页面 parent.location.href="/url" 在父页面打开新页面 top.location.href="/url" 在顶层页面打开新页面 有些时候可能会遇到无法跳转的问题,这需要正确使用上面的跳转用法。 比如在前台有人会用target和iframe来实现提交表单数据但不跳转 <form action="" method="post" target="form_iframe"> <input type="text" id="" name="text" /> <input type="submit" id="" name="" value="提交" /> </form> <iframe id="form_iframe" name="form_iframe" style="display:none;"></iframe> 此时如果在后台使用windows.location.href="/url

前端跨域问题解决过程记录

橙三吉。 提交于 2020-01-20 02:12:50
先对自己说两句闲话,变懒了,很久没有记录自己的工作了,希望不忘初衷。 最近我有这样一个需求,我们是设备软件公司,因此有一个功能就是修改自己的管理口IP和端口,要求修改完成后跳转到新的页面,这里会出现一个问题,就是原有的页面上要通信新的IP和端口,这就涉及到跨域问题,跨域问题解决网上有很多种,我在此只记录我使用过的两种。 我们工程的架构是前端通过Apache反向代理发送到后端,因此cors这种跨域方法,我们应该对Apache做cors的配置(原以为是后端做cors配置)还有一些相关配置,大家百度就好,需要在Apache上添加以下代码: <Directory /> Header set Access-Control-Allow-Origin * </Directory> 配置后重启Apache,我们还需要后端配合做一个事情,因为这个时候我们能够调用新的IP的url,但是浏览器检测到跨域的时候,会发送一个请求方式为OPTIONS的预检查url,这个url需要后端取消头信息检测,然后返回成功后,浏览器才会发送一个真实的url,这样我们的跨域访问才会成功 这样处理过后我们就可以在任何页面里调用我们的IP,说实话是很不安全的,当然 * 是可以改为一个固定的url,这样只能在固定url页面里跨域调用我们的功能,但是这个不适用于我们本次需求,或者能做但是比较麻烦,因为这样我要麻烦后端先把这个

how can i load <script>'s into an iframe?

孤人 提交于 2020-01-19 23:30:41
问题 I've got the logic working to append into my iframe from the parent this works: $('#iframe').load(function() { $(this).contents().find('#target').append('this text has been inserted into the iframe by jquery'); }); this doesn't $('#iframe').load(function() { $(this).contents().find('body').append('<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>'); }); .lf The problem is something to do with the inserted script tags not being

iframe: 我们来谈一谈

好久不见. 提交于 2020-01-19 17:03:04
【转】: https://segmentfault.com/a/1190000004502619#articleHeader6 某大咖说: "iframe是能耗最高的一个元素,请尽量减少使用" 某大牛说: "iframe安全性太差,请尽量减少使用" ... wtf, 你们知不知道你们这样浇灭了多少孩纸学习iframe的热情和决心。 虽然,你们这样说的我竟无法反驳,但是iframe强大功能是不容忽视的。 可以看看各大邮箱网站是否还在使用iframe,查查知乎 iframe . iframe不死,我心不灭。现在给大家安利一下iframe. iframe基本内涵 通常我们使用iframe直接直接在页面嵌套iframe标签指定src就可以了。 <iframe src="demo_iframe_sandbox.htm"></iframe> 但是,有追求的我们,并不是想要这么low的iframe. 我们来看看在iframe中还可以设置些什么属性 iframe常用属性: 1.frameborder:是否显示边框,1(yes),0(no) 2.height:框架作为一个普通元素的高度,建议在使用css设置。 3.width:框架作为一个普通元素的宽度,建议使用css设置。 4.name:框架的名称,window.frames[name]时专用的属性。 5.scrolling:框架的是否滚动。yes

前端跨域总结

不打扰是莪最后的温柔 提交于 2020-01-19 16:20:37
1.跨域的定义 只要协议、域名、端口有任何一个不同,就会被当做为不同的域,如果从A域名访问B域名上的资源就叫做跨域。 下面我们来看下几种跨域的方法: 2.document.domain 浏览器的同源策略有一些限制,第一,不能通过ajax方法去请求不同源的资源;第二,浏览器中不同域的框架之间是不能进行JS交互的。假如有一个页面A,地址是 http://www.domain.cn/A.html ,在这个页面里有个iframe,它的地址是 http://domain.cn/B.html, 显然A和B是不同域的,所以我们没法通过JS来访问iframe中的数据和方法。 这种情况就就可以用document.domain来解决。 解决方法就是把 http://www.domain.cn/A.html 和 http://domain.cn/B.html 的document.domain设成相同的域名,需要注意的是, 我们只能把document.domain设置成自身或更高一级的父域,且主域必须相同。 在A中我们把设置document.domain: <iframe id = "iframe" src="http://domain.cn/B.html" onload = "test()"></iframe> <script type="text/javascript"> document

Iframe causes Can't Verify CSRF Token Authenticity n Rails

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-19 06:21:54
问题 I have a webapp that is loaded through an iframe using phonegap 2.3.0 for Windows Phone 8 SDK. The problem with loading it through the iframe is that it causes Can't verify CSRF token authencity on the Rails side when I send a $.post() request. I tried a couple of approaches such as overwrite the $.post() to use $.ajax() to setHeaderRequest with the token, and also $.ajaxSetup() When I disable protect_from_forgery or verify_authenticity_token , the app loads correctly. I believe the problem

Iframe causes Can't Verify CSRF Token Authenticity n Rails

只谈情不闲聊 提交于 2020-01-19 06:20:26
问题 I have a webapp that is loaded through an iframe using phonegap 2.3.0 for Windows Phone 8 SDK. The problem with loading it through the iframe is that it causes Can't verify CSRF token authencity on the Rails side when I send a $.post() request. I tried a couple of approaches such as overwrite the $.post() to use $.ajax() to setHeaderRequest with the token, and also $.ajaxSetup() When I disable protect_from_forgery or verify_authenticity_token , the app loads correctly. I believe the problem