我能按一下“按钮”吗;“后退”;用javascript在chrome中创建按钮
如果我想加入m.facebook.com,我想帮助你了解如何进入chrome的上一页 现在让我向您展示我的代码:我能按一下“按钮”吗;“后退”;用javascript在chrome中创建按钮,javascript,google-chrome,google-chrome-extension,Javascript,Google Chrome,Google Chrome Extension,如果我想加入m.facebook.com,我想帮助你了解如何进入chrome的上一页 现在让我向您展示我的代码: var host = "http://www.google.com"; // here you put the URL that you want to be redirected chrome.webRequest.onBeforeRequest.addListener( function(details) { return {r
var host = "http://www.google.com"; // here you put the URL that you want to be redirected
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
return {redirectUrl: host + details.url.match(/^https?:\/\/[^\/]+([\S\s]*)/)[1]}; //where it says "host" you put the name of the var that you have set above to the URL that you want to be redirected
},
{
urls: [
"*://m.facebook.com/*" // here you put the URL that you want to block.
],
types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]
},
["blocking"]
);
显示
{
"name": "Facebook Notification Block",
"description": "Block Notification",
"version": "1.0",
"manifest_version": 2,
"background": {
"scripts": [
"background.js"
]
},
"permissions": [
"webRequest",
"*://facebook.com/*",
"*://m.facebook.com/*",
"*://www.facebook.com/*",
"webRequestBlocking"
]
}
有了这段代码,当我安装了扩展后,我可以“阻止”m.facebook.com并从我的Chrome浏览器重定向到“www.google.com”。但我只想转到上一页
更新1:
就像克里斯托弗说的,我试过这些密码
添加到清单权限“历史记录”
我把background.js做成这样
var goBack = function() {
window.history.back();
}
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
return {goBack};
},
{
urls: [
"*://m.facebook.com/*" // here you put the URL that you want to block.
],
types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]
},
["blocking"]
);
但是我不能找出我的错误
var goBack = function() {
window.history.back();
}
这就是您的意思吗?您可以使用chrome.history API扩展来读取历史记录,我想您可以从中获得上一页
@ZigMandel尽管我尽力了,但还是没能成功。我会把更新后的代码上传到你在请求之前返回的地方。你需要知道更多的javascript来编程。