是否可以在两个单独的页面上运行两个内容脚本? [英] Is it possible to have two content scripts run on two separate pages?
本文介绍了是否可以在两个单独的页面上运行两个内容脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有两个内容脚本, codeA.js
和 codeB.js
。我想知道是否可以在 http://上运行 codeA.js
www.example.com 并在上运行 codeB.js
http://www.domain.com 。
Say I have two content scripts, codeA.js
and codeB.js
. I am wondering if it possible to run codeA.js
on http://www.example.com and have codeB.js
run on http://www.domain.com.
是否可以设置我的 content_scripts
在 manifest.json
文件中:
Would it be possible to set my content_scripts
in the manifest.json
file to:
"content_scripts": [
{
"matches": ["http://www.example.com", "http:www.domain.com"],
"js": ["codeA.js", "codeB.js"]
}
]
然后有每个脚本检查页面当前所在的URL?如果是这样,我将如何进行此操作?
and then have each script check to see which URL the page currently sits at? If so, how would I go about doing this?
更新:
我尝试使用以下代码
UPDATE:
I have tried using the following code
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!");
}
但我一直在你正在使用谷歌
。
推荐答案
请注意 content_scripts
是 array :
"content_scripts": [
{
"matches": ["http://www.example.com/*"],
"js": ["codeA.js"]
},
{
"matches": ["http://www.domain.com/*"],
"js": ["codeB.js"]
}
]
这篇关于是否可以在两个单独的页面上运行两个内容脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文