popup-chrome扩展中的背景页面 [英] Background Page in popup- chrome extension

查看:333
本文介绍了popup-chrome扩展中的背景页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在弹出窗口中嵌入了一个动态网页。目前它的工作和每次弹出被加载的网页再次加载,因此我失去了我在弹出的网页上做的工作。虽然它很好,但我希望这个网页仍然在后台加载,我只是点击弹出窗口显示它。要做到这一点,我从我的弹出页面(脚本+ html)完整的代码复制到background.html。现在我应该如何在弹出窗口中完全访问页面并直接显示(我也想从后台页面显示html)



谢谢


<解决方案

Popups与背景页面处于相同的过程(扩展过程),一个页面可以获取另一个页面的DOM窗口。弹出窗口通过调用 chrome.extension.getBackgroundPage()获取后台页面。因此,每次打开弹出窗口时,只需读取并写入背景页面上的某个变量,例如 chrome.extension.getBackgroundPage()。enteredData =value;

或者,您可以使用 HTML5 localStorage 即使在浏览器关闭后也能存储变量;例如 localStorage ['enteredData'] =价值


I am embedding a dynamic webpage in a popup. Currently its working and every time popup is loaded the webpage is loaded again, thus me losing the work i did on the webpage in popup. Though its fine, but i want that webpage remain loaded in background and i just show it in popup on click. to do this i copied complete code from my pop up page(script+html) to background.html. Now how should i access the page completely in popup and show directly(i want to show html also-from background page)

Thanks

解决方案

Popups live in the same process (the extension process) as the background page, and one page can get the DOM Window of the other. A popup gets the background page by calling chrome.extension.getBackgroundPage(). So every time you open the popup, just read and write to some variable on the background page, for example chrome.extension.getBackgroundPage().enteredData = "value";.

Alternately, you can use HTML5 localStorage to store variables even after the browser is shut down; e.g. localStorage['enteredData'] = "value".

这篇关于popup-chrome扩展中的背景页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆