gpt4 book ai didi

javascript - 是否可以在两个单独的页面上运行两个内容脚本?

转载 作者:行者123 更新时间:2023-11-30 17:18:27 26 4
gpt4 key购买 nike

假设我有两个内容脚本,codeA.jscodeB.js。我想知道是否可以在 http://www.example.com 上运行 codeA.js并在 http://www.domain.com 上运行 codeB.js .

是否可以将 manifest.json 文件中的 content_scripts 设置为:

"content_scripts": [
{
"matches": ["http://www.example.com", "http:www.domain.com"],
"js": ["codeA.js", "codeB.js"]
}
]

然后让每个脚本检查页面当前位于哪个 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!");
}

但我一直收到您正在使用 google

最佳答案

请注意,content_scripts 是一个数组:

"content_scripts": [
{
"matches": ["http://www.example.com/*"],
"js": ["codeA.js"]
},
{
"matches": ["http://www.domain.com/*"],
"js": ["codeB.js"]
}
]

关于javascript - 是否可以在两个单独的页面上运行两个内容脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25634572/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com