Google chrome extension 花式设置选项和popup.html之间的交互

Google chrome extension 花式设置选项和popup.html之间的交互,google-chrome-extension,Google Chrome Extension,my extensions的特点是在popup.html中包含一个简单的框架 根据用户在options.html中设置的设置(由[fancy settings]支持),框架url应相应更改 例如: 如果是国家=德国 然后将以下框架包括到 var n=Math.floor(Math.random()*11); 文件。写(“”) 如果country=Polska,则使用不同的框架url 我怎样才能意识到这一点 我通读了有关奇特设置的文档,但没有完全理解。我假设您正在使用此设置。基于此,我认为您的

my extensions的特点是在popup.html中包含一个简单的框架

根据用户在options.html中设置的设置(由[fancy settings]支持),框架url应相应更改

例如:

如果是国家=德国

然后将以下框架包括到


var n=Math.floor(Math.random()*11);
文件。写(“”)
如果country=Polska,则使用不同的框架url

我怎样才能意识到这一点


我通读了有关奇特设置的文档,但没有完全理解。

我假设您正在使用此设置。基于此,我认为您的代码应该如下所示:

var settings = new Store("settings", {
    "country": "Deutschland",
});

var country = settings.get('country');
var n = Math.floor(Math.random()*11);

if(country == 'Deutschland') {
   document.write("<iframe src='http://sms.dynamicdrive.de/sms.php?" + n + "blablabla' scrolling='no'></iframe>");
} else if(country == 'Poland') {
   document.write("<iframe src='http://some.url.pl/sms.php?" + n + "blablabla' scrolling='no'></iframe>");
}
var settings=新存储(“设置”{
“国家”:“德国”,
});
var country=settings.get('country');
var n=Math.floor(Math.random()*11);
如果(国家==“德国”){
文件。填写(“”);
}如果(国家=‘波兰’){
文件。填写(“”);
}

只需替换URL、存储名称(如果您不使用默认的“设置”存储)和默认国家/地区值。

您好kdzwinel,非常感谢您的发布。为了理解它,我有一些问题。此代码应该进入,对吗?然后我还需要我的吗?我不认为我已经更改了花式设置的默认设置。我可以参考我的设置。但是,它不起作用。Popup.html打开but不显示任何帧。是的,此代码应该进入popup.html,您不需要background.html。在使用
store
class之前,只需包含
fancy settings/source/lib/store.js
。如果出现问题,请使用“检查弹出”功能(右键单击扩展图标)和检查控制台是否有错误。我很高兴地说,它现在可以工作了!我什么时候需要background.html?据我所知,background.html的意义是持续检查状态或传递数据,而在我的情况下,用户选择的设置就是这样。那么background.html为什么过时了呢?RegardsBackground当扩展需要一些脚本在后台fg中始终运行时,使用页面。当需要不断检查某些API的更改时,不需要这样的页面,因为每次打开弹出窗口时,都会加载当前设置。如果用户要更改设置并打开弹出窗口,则其新设置将已经存在。
var settings = new Store("settings", {
    "country": "Deutschland",
});

var country = settings.get('country');
var n = Math.floor(Math.random()*11);

if(country == 'Deutschland') {
   document.write("<iframe src='http://sms.dynamicdrive.de/sms.php?" + n + "blablabla' scrolling='no'></iframe>");
} else if(country == 'Poland') {
   document.write("<iframe src='http://some.url.pl/sms.php?" + n + "blablabla' scrolling='no'></iframe>");
}