Koo*_*ing 1 javascript google-chrome google-chrome-extension content-script
假设我有两个内容脚本,codeA.js并且codeB.js. 我想知道是否可以在http://www.example.comcodeA.js上运行并在http://www.domain.com上运行。codeB.js
是否可以将文件content_scripts中的my 设置manifest.json为:
"content_scripts": [
{
"matches": ["http://www.example.com", "http:www.domain.com"],
"js": ["codeA.js", "codeB.js"]
}
]
Run Code Online (Sandbox Code Playgroud)
然后让每个脚本检查页面当前位于哪个 URL?如果是这样,我将如何去做这件事?
更新:
我尝试使用以下代码
if(document.location == "http://*.google.com/*" || "https://*.google.com/*") {
alert("you are using google");
} else if(document.location == "http://*.yahoo.com/*" || "https://*.yahoo.com") {
alert("you are using yahoo!");
}
Run Code Online (Sandbox Code Playgroud)
但我不断得到you are using google。
请注意,这content_scripts是一个数组:
"content_scripts": [
{
"matches": ["http://www.example.com/*"],
"js": ["codeA.js"]
},
{
"matches": ["http://www.domain.com/*"],
"js": ["codeB.js"]
}
]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
539 次 |
| 最近记录: |