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

珠海百度快速优化独立站seo怎么做

珠海百度快速优化,独立站seo怎么做,怎么把网站做漂亮,wordpress单栏极简开发插件的都知道插件的content scripts和top window只共享Dom不共享window和其他数据,如果想拿挂载在window的数据还有点难度,下面会通过事件的方式传递cs和top window之间的数据写一个例子 代码 manifest.json 这里只搞了2个js,content.…

开发插件的都知道插件的content scripts和top window只共享Dom不共享window和其他数据,如果想拿挂载在window的数据还有点难度,下面会通过事件的方式传递cs和top window之间的数据写一个例子

代码

manifest.json

这里只搞了2个js,content.js是content scripts,main.js是在top window里运行的

{"version": "0.0.1","author": "apades","name": "ext-hack","description": "","manifest_version": 3,"content_scripts": [{"matches": ["<all_urls>"],"js": ["content.js"],"run_at": "document_end","all_frames": true},{"matches": ["<all_urls>"],"js": ["main.js"],"run_at": "document_end","world": "MAIN"}]
}

content.js

async function sendExtMessage(type, data) {window.dispatchEvent(new CustomEvent('ext-req', { detail: { type, data } }))return new Promise((res) => {function handleResponse(e) {const detail = e.detailif (detail.type == type) {window.removeEventListener('ext-res', handleResponse)return res(detail.data)}}window.addEventListener('ext-res', handleResponse)})
}// 暴露到content script的window里测试
window.sendExtMessage = sendExtMessage

main.js

window.addEventListener('ext-req', async (e) => {const { type, data } = e.detailswitch (type) {case 'run-code': {let fn = new Function(`return (${data.function})(...arguments)`)let rs = await fn(...(data.args ?? []))sendExtResponse(type, rs)break}}
})function sendExtResponse(type, data) {window.dispatchEvent(new CustomEvent('ext-res', {detail: { type, data },}))
}

运行测试

首先我先在top window里随便写个window.a的值
在这里插入图片描述
然后切换到ext-hack的window里,再测试sendExtMessage
在这里插入图片描述
然后发现可以拿到top window的数据了;以上方法还能传入content script window里的对象参数到top window里使用,也可以传入异步方法
在这里插入图片描述

最后要说的

通过事件里互相传的数据会经过插件内部的序列化,地址、Object.defineProperty都是不共享的。而且这个方法相较于script标签插入,可以绕开doc response的Content-Security-Policy

http://www.shuangfujiaoyu.com/news/52171.html

相关文章:

  • 学校网站建设目的是什么意思百度浏览器手机版
  • 网站建设_seo技术支持外贸网站推广seo
  • 建立网站需要分几部进行收录网站的平台有哪些
  • 安庆有做网站的吗企业整站优化
  • iis架设jsp网站东莞seo网站管理
  • 四川超宇建设集团有限公司网站东莞seo外包公司哪家好
  • 怎样靠做网站赚钱吗互联网营销师培训教程
  • 企业官方网站是什么培训心得体会范文大全1000
  • 佛山专业网站建设哪家好品牌建设的五个要素
  • 展示设计网站有哪些google搜索引擎官网
  • 360建筑网如何删除简历济南网站优化
  • 可以做推广的网站有哪些seo人人网
  • 找公司做网站要注意什么问题数据分析
  • 网络营销网站开发广州搜索seo网站优化
  • 蓝色门户网站湖南 seo
  • 如何抄袭网站seo搜索引擎的优化
  • html和css制作简单网页代码合肥网站优化公司
  • 免费教做面食的网站现在怎么做网络推广
  • 网站建设com网站服务器
  • 如何做楼盘网站网站推广交换链接
  • 网站忧化技巧百度怎么推广产品
  • 网站怎么做二维码链接地址网站seo诊断优化方案
  • 网站的制作建站人广告传媒公司
  • 兄弟们来个能看的潮州seo
  • 单位网站查询工资链接怎么做临沂做网络优化的公司
  • 垂直网站做排名想学编程去哪里找培训班
  • 北洼路网站建设最好的推广平台排名
  • 媒体平台推广百度seo关键词优化推荐
  • asp做网站计数器百度的营销策略
  • 做网站的标准seo服务 文库