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

江苏品牌网站建设电话做网站的图片从哪里找

江苏品牌网站建设电话,做网站的图片从哪里找,wordpress与知更鸟区别,最新装修风格2023简单大气的使用 postMessage API 来实现跨窗口#xff08;跨域#xff09;的消息传递。postMessage 允许你安全地发送消息到其他窗口#xff0c;包括嵌套的 iframe#xff0c;而不需要担心同源策略的问题。 发送消息#xff08;父应用#xff09; 1. 父应用#xff1a;发送消息给…使用 postMessage  API 来实现跨窗口跨域的消息传递。postMessage 允许你安全地发送消息到其他窗口包括嵌套的 iframe而不需要担心同源策略的问题。 发送消息父应用 1. 父应用发送消息给子应用 父应用可以通过 postMessage 将消息发送给子应用。需要注意的是发送消息时需要指定目标窗口和目标窗口的来源即目标 iframe 的 origin以确保安全性。 iframe.contentWindow.postMessage(message, targetOrigin) 使用 postMessage 向子应用发送消息。message 是要发送的数据可以是任何 JavaScript 对象。targetOrigin 是目标窗口的源例如http://child-app.com它确保消息只发送到具有这个源的窗口。 2、接收消息子应用 子应用通过监听 message 事件来接收父应用发送的消息。收到消息后子应用可以根据消息中的 type 字段来执行不同的操作。 示例父应用与子应用通信 1. 父应用发送消息给子应用 父应用通过 postMessage 向 iframe 中的子应用发送一个包含 type 的消息。我们还可以通过 targetOrigin 来确保消息只发送到指定的子应用。 !-- 父应用 -- !DOCTYPE html html langen headmeta charsetUTF-8meta nameviewport contentwidthdevice-width, initial-scale1.0titleParent App/title /head bodyh1Parent Application/h1!-- iframe 中嵌套子应用 --iframe idchildIframe srchttp://child-app.com width600 height400/iframebutton onclicksendMessageToChild()发送消息到子应用/buttonscript// 发送消息到子应用function sendMessageToChild() {const iframe document.getElementById(childIframe);const message {type: CLEAR_INPUT, // 消息类型data: { message: 请清空输入框 }};// 使用 postMessage 发送消息到子应用iframe.contentWindow.postMessage(message, http://child-app.com); // 子应用的 origin}/script /body /html2. 子应用接收父应用发送的消息 子应用会监听 message 事件接收到消息后可以处理它。通常可以根据 message.type 来决定如何处理消息。 !-- 子应用 (iframe 内容) -- !DOCTYPE html html langen headmeta charsetUTF-8meta nameviewport contentwidthdevice-width, initial-scale1.0titleChild App/title /head bodyh1Child Application/h1input typetext idinputField placeholder请输入内容...script// 监听父应用发送的消息window.addEventListener(message, function(event) {// 验证消息的来源if (event.origin ! http://parent-app.com) {return; // 如果消息来源不正确则忽略}const message event.data;console.log(Received message from parent:, message);// 根据消息的 type 执行不同操作if (message.type CLEAR_INPUT) {document.getElementById(inputField).value ; // 清空输入框}});/script /body /html如何在vue本地项目进行iframe测试通讯 1、新建一个iframe.vue页面为父页面 // 父应用 templatediv classact-formiframe :srcsrc idchildIframe width600 height400/iframeel-button clicksendMessage向iframe发送信息/el-button/div /templatescriptexport default {data () {return {src: ,}},created() {// 当前我本地运行的端口为 localhost:8080 需要根据实际情况调动this.src http:localhost:8080/home?id18 },methods: {sendMessage () {const iframe document.getElementById(childIframe);const message {type: CLEAR_INPUT, // 消息类型data: { message: 请清空输入框 }};// 使用 postMessage 发送消息到子应用iframe.contentWindow.postMessage(message, this.src); // 子应用的origin},},} } /script 2、子应用  !-- 子应用 (iframe 内容) -- templatediv // 内容区域/div /templatescriptexport default {data () {return {},created() {// 在外部vue的window上添加postMessage的监听并且绑定处理函数handleMessagewindow.addEventListener(message, this.handleMessage)},methods: {handleMessage (event) {// 根据上面制定的结构来解析iframe内部发回来的数据// 验证消息的来源if (event.origin ! http://parent-app.com) {return; // 如果消息来源不正确则忽略}const message event.data;console.log(Received message from parent:, message);// 根据消息的 type 执行不同操作if (message.type CLEAR_INPUT) {// 在这里执行你需要的逻辑}});}}beforeDestroy(){ // 页面关闭移除监听window.removeEventListener(message, this.handleMessage);} /script
http://www.w-s-a.com/news/435834/

相关文章:

  • 做网站首页多少钱免费版企业邮箱注册
  • ppp模式在网站建设的南昌专业做网站公司哪家好
  • 泰安网站建设制作电话号码百度sem竞价托管公司
  • 苏网站建设网页设计和网页美工
  • 跨境电商平台网站广州地铁站路线图
  • 吉林省交通建设集团有限公司网站企业网站推广的策略有哪些
  • 网站内链怎么做更好郑州网站建设哪家便宜
  • 建设大型购物网站运城哪里做网站
  • php企业网站通讯录管理系统做网站在线支付系统多少钱?
  • 怎么区分用vs和dw做的网站贝贝网网站开发背景
  • 无锡网站建设制作建设信息网查询
  • 彩票系统网站开发建设人力资源网官网
  • 有专门下载地图做方案的网站吗网站建设平台计划书
  • 网站闭站保护10个著名摄影网站
  • 安徽省建设工程信息网官网首页网站关键词排名优化工具
  • 深圳网站建设 百业网站专题教程
  • 公司seo是指什么意思如何来做网站优化
  • 化妆品网站建设平台的分析湖南网站搜索排名优化电话
  • 织梦网站修改教程视频教程管理类网站开发价格
  • 如何让新网站快速收录企业建站的作用是什么
  • 在线制作简历的网站做的最好的微电影网站
  • h5制作的网站网络游戏投诉平台
  • 做外贸网站好还是内贸网站好珠海新盈科技有限公 网站建设
  • php和网站开发网络软营销
  • 大型做网站的公司有哪些wordpress注册链接无效
  • 推荐门户网站建设公司网站开发移动端
  • 公司网站的栏目设置成都十大监理公司排名
  • 安溪住房和城乡建设网站关岭县建设局网站
  • 网站域名注销备案徐州房产网
  • 筑聘网windows优化大师自动安装