*新闻详情页*/>
日期:2021-02-23 类型:科技新闻 我要分享
关键词:通道抠图,怎么在图片上编辑文字,创客贴作图神器,免费图片设计制作在线,背景透明图制作
本文详细介绍了详解html5 postMessage处理跨域通讯的难题,共享给大伙儿,实际以下:
实际效果图
postmessage分析HTML5出示了新式体制PostMessage完成安全性的跨源通讯. 英语的语法 otherWindow.postMessage(message, targetOrigin, [transfer]);
otherWindow: 别的对话框的1个引入, 例如IFRAME的contentWindow特性, 实行,window.open回到的对话框目标. message: 即将推送到别的对话框的数据信息. targetOrigin:根据对话框的origin特性来特定哪些对话框能接受到信息恶性事件, 其值能够是标识符”*”(表明无尽制)或1个URL transfer:是1串和message另外传送的Transferable目标. 这些目标的全部权将被迁移给信息的接受方, 而推送1放将已不保有一定的有权.element.addEventListener(event,fn,useCaption ); 3个主要参数 event 恶性事件 例如click mouseenter mouseleave 回调函数涵数 useCaption用于叙述是冒泡還是捕捉。默认设置值是false,即冒泡传送。 当值为true,便是捕捉传送。完成方法
主页面 main.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF⑻"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>跨域数据信息浏览</title> <script type="text/javascript"> window.addEventListener('message',function(e){ console.log("e--->",e); const data = e.data; document.getElementById('main1').style.backgroundColor=e.data; },false) </script> </head> <body> <div id="main1" style="width:200px;height:200px;margin:100px;border:solid 1px #000;"> 我是主页面,等候接受iframe的传送 </div> <div style="margin:100px;"> iframe <iframe src="http://localhost:3000/iframe.html" width="800px" height="300px" ></iframe> </div> </body> </html>
iframe页面
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF⑻"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style type="text/css"> html,body{ height:100%; margin:0px; } </style> </head> <body style="height:100%;"> <div id="frame" style="height:200px; width:200px;background-color:rgb(204, 204, 0)" onclick="changeColor()"> 点一下更改色调 </div> <script type="text/javascript"> function changeColor(){ var frame = document.getElementById('frame'); var color=frame.style.backgroundColor; if(color=='rgb(204, 102, 0)'){ color='rgb(204, 204, 0)'; }else{ color='rgb(204,102,0)'; } console.log("frame===>",frame); console.log("color",color); frame.style.backgroundColor=color; window.parent.postMessage(color,'*'); } </script> </body> </html>
以上便是本文的所有內容,期待对大伙儿的学习培训有一定的协助,也期待大伙儿多多适用脚本制作之家。
Copyright © 2002-2020 通道抠图_怎么在图片上编辑文字_创客贴作图神器_免费图片设计制作在线_背景透明图制作 版权所有 (网站地图) 粤ICP备10235580号