简体   繁体   English

从另一个JS文件中的函数调用变量

[英]Calling a variable from a function in a different JS file

I am working on a chrome extension and I am stuck. 我正在开发Chrome扩展程序,但遇到问题。 I am not sure if this is even possible but this is what I need to have done. 我不确定这是否可能,但这是我需要做的。 Basically the user click on the chrome extension and panel opens up (popup.html). 基本上,用户单击chrome扩展名,然后打开面板(popup.html)。 The user is shown a list of images from the web and the user can select the ones they want to edit. 向用户显示了来自网络的图像列表,并且用户可以选择他们要编辑的图像。 popup.html loads popup.js. popup.html加载popup.js。 popup.js contains functions and inside those functions are some variable. popup.js包含函数,并且在这些函数内部是一些变量。 Now there is a button in popup.html that takes you to another panel called filters.html. 现在popup.html中有一个按钮,可将您带到另一个名为filter.html的面板。 This is where editing goes. 这就是编辑的地方。 I am trying to pass the selected images from popup.html to filters.html and I am trying to call that array of images that was gathered in popup.js when popup.html loaded but its null. 我试图将选定的图像从popup.html传递到filters.html,并且试图调用popup.html加载时在popup.js中收集的图像数组,但其值为null。 What is wrong is this even possible? 这有什么可能吗? When a new html page opens up does that mean it loses track of what happened in the last html page and therefore it loses also track of whatever .js files ran in that same page? 当一个新的html页面打开时,这是否意味着它失去了对最后一个html页面中发生的事件的跟踪,因此也失去了对该页面中运行的任何.js文件的跟踪?

A new and better way is to use chrome extension storage . 一种新的更好的方法是使用chrome扩展存储 You can store the data from one page and u can read it in other page as data will be stored in chrome itself. 您可以存储一页中的数据,而您可以在另一页中读取数据,因为数据将存储在chrome本身中。 Hope it helps 希望能帮助到你

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

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