我的Chrome扩展程序有两个文件:内容和后台脚本.我需要将jQuery添加到内容脚本,从cdn和lodash到cdn的后台脚本.
在我的清单中,我试图从cdn添加lodash,如下所示:
"background": {
"scripts": ["background.js", "https://cdn.jsdelivr.net/lodash/4.13.1/lodash.min.js"]
},
"content_security_policy": "script-src 'self' https://cdn.jsdelivr.net; object-src 'self'"
Run Code Online (Sandbox Code Playgroud)
但这没有帮助.
我的内容文件从后台文件注入到页面中:
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (changeInfo.status == 'complete') {
chrome.tabs.insertCSS(null, {file: "mainStyles.css"});
chrome.tabs.executeScript(null, {
code: 'var config = ' + JSON.stringify(config)
}, function() {
chrome.tabs.executeScript(null, { file: "https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js" }, function() {
chrome.tabs.executeScript(null, { file: "content.js" })
});
});
}
});
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我试图从cdn中包含jQuery,但这种方式也没有包括在内.
也许有人知道如何做到这一点?提前谢谢了!
在我的角度为1.5的应用程序中有两个组件.父母一:
angular.
module('myApp').
component('myContainer', {
bindings: {
saySomething: '&'
},
controller: ['$scope', function MyController($scope) {
var containerCtrl = this;
containerCtrl.saySomething = function saySomething() {
containerCtrl.sentence = "Hello, world";
console.log(containerCtrl.sentence);
};
}]
});
Run Code Online (Sandbox Code Playgroud)
还有一个孩子:
angular.
module('myApp').
component('myButton', {
bindings: {
onClick: '&'
},
template:
'<div>' +
'<a class="button" href="#">Say Something</a>' +
'</div>'
});
Run Code Online (Sandbox Code Playgroud)
这是我的index.html:
<my-container>
<my-button ng-click="$ctrl.saySomething()"></my-button>
</my-container>
Run Code Online (Sandbox Code Playgroud)
问题是:如何通过单击子组件中的按钮从父组件调用函数saySomething()?现在它不起作用.我在这里看到了类似的问题,但这并没有解决我的问题.在此先感谢您的帮助!
PS如果有任何类似的问题,请告诉我.Tnanks!
在我的chrome扩展程序中,我需要使用chrome存储。首先,在后台脚本中创建一个对象并将其添加到chrome存储中,然后从那里获取对象并返回。像这样:
...
var obj = {};
chrome.storage.local.set(obj, function () { });
...
var data = getData(obj); // I want my object to be returned here
var returnedData = null;
function getData(obj) {
chrome.storage.local.get(obj, function(result) {
returnedData = result; // here it works, I can do something with my object
});
return returnedData; // here it doesn't work
}
Run Code Online (Sandbox Code Playgroud)
据我从这里 了解到chrome.storage.local.get
,它的后果是异步的。但是,有什么方法可以从Chrome存储中获取某些东西并将其退还吗?我的意思是也许我应该包装chrome.storage.local.get
另一个函数?
提前谢谢了!