iframe 跨域访问以及操作
来源:互联网 发布:学理科的软件 编辑:程序博客网 时间:2024/06/05 17:18
按情境分
1、不跨域时
2、主域相同、子域不同时
3、主域不同
访问iframe: contentWindow
访问父级:parent
跨域时
1. 是同主域下面,不同子域之间的跨域
如:xx.tecent.com与yy.tecent.com之间有同主域tecent.com
同主域,不同子域跨域,设置相同的document.domian就可以解决;
例如:http://a.tecent.com/main.html
<!doctype html><html><head><meta charset="utf-8"><title>无标题文档</title></head><body><iframe src="http://b.tecent.com/iframe.html" id=“iframe”></iframe><script> document.domain="tecent.com";
var name="main.html";
//访问iframe里的元素
<span style="color: rgb(237, 28, 36); font-family: simsun; font-size: 14px; line-height: 21px;">document.getElementById("iframe").contentWindow.document.getElementById("</span><span style="color: rgb(237, 28, 36); font-family: simsun;">childNode</span><span style="color: rgb(237, 28, 36); font-family: simsun; line-height: 21px;">").value</span><span style="color: rgb(237, 28, 36); font-family: simsun; line-height: 21px;">;</span><span style="color: rgb(237, 28, 36); font-family: simsun; font-size: 14px; line-height: 21px;"></span></script></body></html>
http://b.tecent.com/iframe.html
<!doctype html><html><head><meta charset="utf-8"><title>无标题文档</title></head><body><span style="white-space:pre"></span><input id="childNode" value="这是iframe页面内容"/><script> document.domain="tecent.com";//访问iframe外页面的元素
alert(parent.name);
</script></body></html>
2.不同主域跨域
暂时没遇到,等以后再补上
0 0
- iframe 跨域访问以及操作
- JS跨域访问操作iframe
- JS跨域访问操作iframe
- iframe跨域访问
- iframe跨域访问
- iframe跨域访问
- iframe跨域访问
- iframe跨域访问
- iframe跨域访问
- iframe跨域访问
- Iframe跨域访问
- iframe表单跨域访问
- iframe跨域访问问题
- iframe跨域互相访问
- js IFRAME 跨域操作
- iframe跨域访问cookie、Session
- iframe中页面跨域访问javascript
- iframe用法 及 跨域访问问题
- 用js+html5画布功能做转盘
- jquery之event.target vs this
- #pragma pack(push,1)与#pragma pack(1)的区别
- UML之对象图
- SQLServer 以备份初始化订阅
- iframe 跨域访问以及操作
- 一看就明白的爬虫入门讲解:基础理论篇
- 详解C中volatile关键字
- ios学习swift第一天,基本语法
- redhat 默认python2.6 升级到2.7
- sicily 1051. Biker's Trip Odomete
- java中读写文件到手机SD卡
- JS的一些实用的方法
- cacti使用详解一