简体   繁体   English

在Chrome扩展程序弹出窗口上显示后窗口变量

[英]Show on Chrome Extension Popup a late window variable

I am still learning about all the Chrome Extension scheme, with background/content/popup scripts. 我仍在使用背景/内容/弹出脚本来了解所有Chrome扩展方案。

I have a page that runs some script on $(document).ready() and it sets a new variable in the window, that i can access in the website like "window.newVariableHere". 我有一个在$(document).ready()上运行一些脚本的页面,它在窗口中设置了一个新变量,我可以在网站中访问“ window.newVariableHere”。 I want to be able to echo the content of this variable whenever i open the Extension popup. 我希望能够在打开扩展弹出窗口时回显此变量的内容。

I tried, in the popup.js (which is being called in my popup.html) do a: 我尝试在popup.js(在我的popup.html中被调用)中执行以下操作:

chrome.extension.getBackgroundPage()

But it wont show the new variable (that i am sure it was created). 但是它不会显示新变量(我确定它是创建的)。 Any ideas on a better way to do this? 对更好的方法有什么想法吗?

Thanks for all the ideas 感谢所有的想法

chrome.extension.getBackgroundPage() gives you the window object of the background page , not the actual displayed website in the current tab. chrome.extension.getBackgroundPage()为您提供背景页面window对象,而不是当前选项卡中实际显示的网站。

Please read the Architecture Overview . 请阅读架构概述 (All Chrome extension developers must read and understand that) (所有Chrome扩展程序开发人员都必须阅读并理解)

You will need a content script, and worse than that, you will need a page-level script since window object of the page is isolated from content scripts. 您将需要内容脚本,更糟糕的是,您将需要页面级脚本,因为页面的 window对象与内容脚本是隔离的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM