Chrome 扩展如何将数据从内容脚本发送到 popup.html [英] Chrome Extension how to send data from content script to popup.html
本文介绍了Chrome 扩展如何将数据从内容脚本发送到 popup.html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道很多帖子都问过这个问题,但老实说我不明白.我是 JavaScript、Chrome 扩展和所有东西的新手,我有这门课.所以我需要制作一个插件,使用跨域请求来计算任何给定页面上的 DOM 对象.到目前为止,我已经能够使用 Chrome 扩展 API 实现这一点.现在的问题是我需要在我的 popup.html 页面上从 contentScript.js 文件中显示数据.我不知道该怎么做,我已经尝试阅读文档,但是在 chrome 中发送消息我就是不明白该怎么做.
以下是到目前为止的代码.
manifest.json
<代码>{"manifest_version":2,"name":"Dom 阅读器","description":"计数 Dom 对象","版本":"1.0",页面动作":{"default_icon":"icon.png","default_title":"Dom 阅读器","default_popup":"popup.html"},背景":{"脚本":["eventPage.js"],持久":假},内容脚本":[{"匹配":["http://pluralsight.com/training/Courses/*", "http://pluralsight.com/training/Authors/Details/*", "https://www.youtube.com/用户/*", "https://sites.google.com/site/*", "http://127.0.0.1:3667/popup.html"],"js":["domReader_cs.js","jquery-1.10.2.js"]//"css":["pluralsight_cs.css"]}],权限":[标签","http://pluralsight.com/*","http://youtube.com/*","https://sites.google.com/*",http://127.0.0.1:3667/*"]
popup.html
<标题>Dom阅读器</title><script src="jquery-1.10.2.js" type="text/javascript"></script><script src="popup.js" type="text/javascript"></script><身体><H1>Dom阅读器</H1><input type="submit" id="readDom" value="读取DOM对象"/><div id="domInfo">