ここで私は2つのJavaScriptファイルを持っていると私はエラーを回避するために、以下のようmanifest.json
を変更:クロム拡張のjavascriptファイルを使用して別のjavascriptファイルに存在するオブジェクトにアクセスするにはどうすればよいですか?
o = {
"timeStamps" : t.slice(),
"messages" : Object.assign({}, a)
}
console.log(o);
help(o.messages, o.timeStamps.length);
function help_final(){
return o;
}
:
{
"matches": [
"*://example.com"
],
"all_frames": true,
"css":[
"css/d.css",
"css/bootstrap.min.css"
],
"js": [
"scripts/jquery.min.js",
"scripts/home/msg.js",
"scripts/home/modify.js"
]
}
今、私は、オブジェクトがmsg.js
ファイルに常駐していると私は唯一の関連する部分を含めています持っています
ここでconsole.log(o)
は問題なく動作しています。だから私はこのオブジェクトo
modified.js
という別のファイルにしたい。
message_object = help_final();
$.getScript("msg.js")
.done(function(script, textStatus) {
console.log(textStatus);
//here i need to access the object o and store it as global variable
})
.fail(function(jqxhr, settings, exception) {
});
$(document).ready(function() {
console.log("ready!");
//I need to access the obj here
console.log(message_object);
});
は、2 jsファイルのバックグラウンドページですか? – juvian
@juvian普通のスクリプトはありません –