如何仅在网站的子目录中加载Protected Sub GridView1_ApplyRowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
Dim Job_ID As Integer = e.Row.FindControl("Job_ID").Text
End Sub
内容脚本。例如:
在: Chrome
不在: https://www.example.com/#!/video/*
所以我不想在主页上加载,而是在视频目录中加载。我已经尝试过像这样的匹配模式,但它不起作用。
https://www.example.com/
我的网址如下:"matches": ["*://*.example.com/*", "*://*.example.com/#!/video/*"]
PS:我还希望在每次来自页面的ajax请求后再次加载脚本。
答案 0 :(得分:1)
问题是"matches"
不支持URL片段(URL哈希),并且无法使用"content_scripts"
部分根据哈希更改自动注入/自动删除脚本,因为页面不是'实际上重新加载了。
从manifest.json中删除整个"content_scripts"
部分,并仅在需要时使用webNavigation API注入/激活内容脚本(需要"permissions: ["webNavigation"]
)。
background.js:
chrome.webNavigation.onCommitted.addListener(function(details) {
injectOrActivate("onCommitted", details);
});
chrome.webNavigation.onHistoryStateUpdated.addListener(function(details) {
injectOrActivate("onHashChange", details);
});
function injectOrActivate(event, details) {
var tabId = details.tabId;
if (details.url.indexOf("#") < 0) {
deactivateContentScript(tabId);
return;
}
chrome.tabs.executeScript(tabId, {code: "injectedStatus"}, function(res) {
if (res[0] != "injected") {
chrome.tabs.executeScript(tabId, {file: "content.js"}, function(res) {
activateContentScript(tabId);
});
} else {
activateContentScript(tabId);
}
}
}
function activateContentScript(tabId) {
chrome.tabs.sendMessage(tabId, {action: "activate"});
}
function deactivateContentScript(tabId) {
chrome.tabs.sendMessage(tabId, {action: "deactivate"});
}
content.js:
var injectedStatus = "injected";
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
switch (msg.action) {
case "activate":
doSomething();
break;
case "deactivate":
stopDoingSomething();
break;
}
});