当前位置: 首页 > news >正文

提供有经验的网站建设企业网站备案资料填写单

提供有经验的网站建设,企业网站备案资料填写单,google官网进入,政务网站模板简单使用 我们通常使用iframe最基本的特性&#xff0c;就是能自由操作iframe和父框架的内容(DOM). 但前提条件是同域. 如果跨域顶多只能实现页面跳转 <iframe src"./iframeA.html"></iframe> 同域 or <iframe src"https://cn.bing.com/"&g…

简单使用

我们通常使用iframe最基本的特性,就是能自由操作iframe和父框架的内容(DOM). 但前提条件是同域. 如果跨域顶多只能实现页面跳转

<iframe src="./iframeA.html"></iframe>  同域
or
<iframe src="https://cn.bing.com/"></iframe> 跨域

iframeA.html

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<body style="height:500px"><div id="iframeAID">我是iframeA</div><input type="text" id="date" value="2022-10-24"/>
</body>
</html>

iframe常用属性

name:框架的名称,window.frames[name]时专用的属性。
src:内框架的地址,可以使页面地址,也可以是图片的地址。
width:框架作为一个普通元素的宽度,建议使用css设置。
height:框架作为一个普通元素的高度,建议在使用css设置。
scrolling:框架的是否滚动。yes,no,auto。
frameborder:是否显示边框,1(yes),0(no)
srcdoc , 用来替代原来HTML body里面的内容。但是IE不支持, 不过也没什么卵用
sandbox: 对iframe进行一些列限制,IE10+支持

获取iframe里的内容

主要的两个API就是contentWindow,和contentDocument,这两个API只是DOM节点提供的方式(即getELement系列对象)

// iframe.contentWindow, 获取iframe的window对象
// iframe.contentDocument, 获取iframe的document对象
<script>window.onload = function(){let obj= document.getElementById("iframe1");// 获取iframe的window对象let objWindow = obj.contentWindowconsole.log(objWindow); console.log(objWindow.document); // 获取iframe的window对象的documentconsole.log(objWindow.document.documentElement); // 获取htmlconsole.log(objWindow.document.head); // 获取headconsole.log(objWindow.document.body); // 获取body// 获取iframe的documentlet objContentDocument = obj.contentDocumentconsole.log(objContentDocument);  // 结合Name属性,通过window提供的frames获取.console.log(window.frames['iframe1'].window);// 修改子页面样式let obj= document.getElementById("iframe1");let box = obj.contentWindow.document.getElementById("iframeAID")box.style.width = "500px";box.style.height = "100px";box.style["backgroundColor"] = "red";// // 获取子页面输入框值console.log(window.frames["iframe1"].document.getElementById("date").value);
}
</script>

在iframe中获取父级内容

同理,在同域下,父页面可以获取子iframe的内容,那么子iframe同样也能操作父页面内容。

在iframe中,可以通过在window上挂载的几个API进行获取.

window.parent 获取上一级的window对象,如果还是iframe则是该iframe的window对象
window.top    获取最顶级容器的window对象,即,就是你打开页面的文档
window.self   返回自身window的引用。可以理解 window===window.self
<script>// 方法一: 父页面可控可以使用window.onload = function(){console.log(window.frames.name);console.log(parent.window.frames.document.querySelectorAll("iframe") );let arr = Array.from(parent.window.frames.document.querySelectorAll("iframe"))arr.forEach(item => {if(window.frames.name === item.name) {console.log(item.id);console.log(item.width);console.log(item.height);console.log(item.src);}})}// 方法二: 建议使用window.onload = function(){parent.window.frames.document.querySelectorAll("iframe").forEach(item => {if(window.frames.location.href === item.src){console.log(item.id, '根据地址判断-- 我是iframeA');}})}
</script>

动态添加 iframe

<script>window.onload = function(){let iframeCon = document.querySelector('#container')let text; //传递的信息let iframe = document.createElement('iframe')iframe.id = "frame"iframe.style = "display:block;"iframe.name="polling"iframe.src="./iframeB.html"iframeCon.appendChild(iframe);}
</script>

iframe样式

默认情况下,iframe会自带滚动条,不会全屏

去掉滚动条

<iframe name="iframe1" id="iframe1" src="./iframeA.html" scrolling="no"></iframe>

设置 iframe的高为body的高

let iframe= document.getElementById("iframe1");
let objWindow = iframe.contentWindow;
let objDoc = objWindow.document;
iframe.height = objDoc.body.offsetHeight;

是否允许iframe设置为透明,allowtransparency 默认为false

<iframe name="iframe1" id="iframe1" src="./iframeA.html" allowtransparency="true"></iframe>

是否允许iframe全屏,allowfullscreen 默认为false

<iframe name="iframe1" id="iframe1" src="./iframeA.html" allowfullscreen="true"></iframe>

iframe安全性探索

iframe出现安全性有两个方面,一个是你的网页被别人iframe,一个是你iframe别人的网页

防嵌套网页

// 使用window.top来防止自己的网页被iframe.这段代码的主要用途是限定自己的网页不能嵌套在任意网页内
if(window != window.top){window.top.location.href = correctURL;
}
// 如果你想引用同域的框架的话,可以判断域名
try{top.location.hostname;  //检测是否出错//如果没有出错,则降级处理if (top.location.hostname != window.location.hostname) { top.location.href =window.location.href;}
} catch(e){top.location.href = window.location.href;
}

在服务器上,对使用iframe的权限进行设置 X-Frame-Options

X-Frame-Options是一个相应头,主要是描述服务器的网页资源的iframe权限。目前的支持度是IE8+有3个选项:
DENY:		当前页面不能被嵌套iframe里,即便是在相同域名的页面中嵌套也不允许,也不允许网页中有嵌套iframe
SAMEORIGIN: iframe页面的地址只能为同源域名下的页面
ALLOW-FROM: 可以在指定的origin url的iframe中加载X-Frame-Options: DENY  拒绝任何iframe的嵌套请求
X-Frame-Options: SAMEORIGIN 只允许同源请求,例如网页为 foo.com/123.php,則 foo.com 底下的所有网页可以嵌入此网页,但是 foo.com 以外的网页不能嵌入
X-Frame-Options: ALLOW-FROM http://s3131212.com 只允许指定网页的iframe请求,不过兼容性较差Chrome不支持

X-Frame-Options其实就是将前端js对iframe的把控交给服务器来进行处理。

//js
if(window != window.top){window.top.location.href = window.location.href;
}
//等价于
X-Frame-Options: DENY//js
if (top.location.hostname != window.location.hostname) { top.location.href =window.location.href;
}
//等价于
X-Frame-Options: SAMEORIGIN

文章转载自:

http://qxxdY99t.ssfq.cn
http://bt09pUOY.ssfq.cn
http://Jd90NAde.ssfq.cn
http://Idi8YezV.ssfq.cn
http://VdxWGd3a.ssfq.cn
http://OKlCdQBo.ssfq.cn
http://kkqkkQPo.ssfq.cn
http://DiSSnLoE.ssfq.cn
http://T1RBfuq8.ssfq.cn
http://35vmntSY.ssfq.cn
http://3Ztzps0S.ssfq.cn
http://MBjQTmqj.ssfq.cn
http://d7bIPHBL.ssfq.cn
http://FoPhLLLR.ssfq.cn
http://5MNv1XNE.ssfq.cn
http://Mby7A28S.ssfq.cn
http://xGXLW3vr.ssfq.cn
http://7RjLIsnC.ssfq.cn
http://0EDvBBlT.ssfq.cn
http://vGIipW8F.ssfq.cn
http://6x65SnT6.ssfq.cn
http://nk419pFe.ssfq.cn
http://XO3hOWHI.ssfq.cn
http://m3ySK2TQ.ssfq.cn
http://04o64KyQ.ssfq.cn
http://DmEKWHaf.ssfq.cn
http://UWi6S7vc.ssfq.cn
http://yrQthrJt.ssfq.cn
http://93caIqzG.ssfq.cn
http://Iy8zgDmn.ssfq.cn
http://www.cdong.cn/news/60/

相关文章:

  • 西安网站运营桂林欣梦网络
  • 信息手机网站模板下载安装网站开发神书
  • 青岛专业公司网站设计平易云 网站建设
  • 免费申请网站 主机 空间网站开发前期调研
  • [8dvd]flash网站源文件 flash整站源码河源今天发生的重大新闻
  • 企业网站的建设哪家比较好莱芜都市网二手
  • 免费生成手机网站个人网站定制
  • 大连网站制作流程门户类网站图片
  • 呼和浩特国风网络昆明做整站优化
  • 网站开发进度设计与阶段目标成都网站建设小公司排名
  • 河北建设官方网站智慧团建系统平台登录入口
  • 成都建站哪家好网站设计中遇到的问题
  • 合肥建设管理学院网站wordpress固定链接打不开
  • 网站建设文案详情郑州哪家公司做网站好
  • 企业官方网站的作用天津互联网网页设计招聘
  • 沈阳自助模板建站要加强网站内容建设
  • 怎么做网站开发外网建筑设计网站
  • 外贸网站怎么营销wordpress 随机文章插件
  • 网站优化排名易下拉稳定做网站收入
  • 天河wap网站建设公司淘宝店铺网站建设可行性报告
  • 网站建设的网站分析怎么写wordpress图标显示
  • xyz域名注册局官方网站区块链app开发价格
  • 做网站的的步骤怎么写上海官网网址
  • 呼和浩特做网站哪家公司好群晖wordpress更新下载失败
  • 网站主页面布局怎么做揭阳seo快速排名
  • 义乌网站建设和制作分销网站有哪些
  • 西安网站网络营销网站dns多久刷新
  • 网站建设费用包括哪些方面装修设计公司公司价格表
  • 怎么建立手机网站做期货在哪个网站看消息
  • 做网站用百度浏览器公司营业执照