Can i click back button in chrome using javascript
I would like to help understand how can I go to the previous page in chrome if I try to join m.facebook.com
Let me show you my code so far:
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"]
);
manifesto
{
"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"
]
}
With this code I can "block" m.facebook.com and redirect to "www.google.com" from the Chrome browser when I installed the extension. But I just want to go to the previous page.
Update1:
As Christopher suggested, I tried these codes
added to the "history" manifest permissions
and i made background.js like this
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"]
);
But I cannot figure out my mistake.
+3
user4544229
source
to share