禁用刷新/后退/前进在自己的浏览器 [英] disable refresh / back / forward in OWN browser
问题描述
有没有办法只能使自己的浏览器(Chrome)不能够去前进/后退/刷新?
Is there a way to only make my OWN browser (Chrome) not be able to go back / forward / refresh?
这会发生,而往往,当即时通讯开发和devtools玩耍(更改HTML和CSS只是尝试的事情了),我有时会不小心刷回或出于习惯打刷新。我希望能够禁用通过某种延伸?
This happens rather often that when Im developing and playing around in devtools (Changing HTML and CSS just to try things out) I sometimes accidentally swipe back or out of habit hit refresh. I would like to be able to disable the back or forward button via some sort of extension?
我不是要禁用任何活动,网站上的按钮,只是对我本地。任何想法?
I am NOT trying to disable the button on any live-website, just for me locally. Any ideas?
推荐答案
如果您想prevent意外导航,就没有必要安装任何扩展。只需打开控制台,并运行以下code:
If you want to prevent accidental navigations, there's no need to install any extension. Just open the console, and run the following code:
window.onbeforeunload = function() {
return 'Want to unload?';
};
有了这个code,你会得到一个确认提示。
With this code, you will get a confirmation prompt.
如果你真的想prevent的页面从通过扩展卸载,请在答案中描述的技术,<一个href=\"http://stackoverflow.com/questions/18684024/how-to-cancel-webrequest-silently-in-chrome-extension\">How取消的WebRequest默默Chrome扩展。
If you really want to prevent the page from unloading via an extension, use the technique described in the answers to How to cancel webRequest silently in chrome extension.
下面是增加了一个按钮,您的浏览器最小演示扩展。点击后,您无法导航到不同的页面了。您仍然可以关闭该选项卡没有任何警告,虽然:
Here's a minimal demo extension that adds a button to your browser. Upon click, you cannot navigate to a different page any more. You can still close the tab without any warning, though:
// background.js
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.webRequest.onBeforeRequest.addListener(function(details) {
var scheme = /^https/.test(details.url) ? 'https' : 'http';
return { redirectUrl: scheme + '://robwu.nl/204' };
// Or (seems to work now, but future support not guaranteed):
// return { redirectUrl: 'javascript:' };
}, {
urls: ['*://*/*'],
types: ['main_frame'],
tabId: tab.id
}, ['blocking']);
});
的manifest.json这个扩展:
manifest.json for this extension:
{
"name": "Never unload the current page any more!",
"version": "1",
"manifest_version": 2,
"background": {
"scripts": ["background.js"],
"persistent": true
},
"browser_action": {
"default_title": ""
},
"permissions": [
"<all_urls>",
"webRequest",
"webRequestBlocking"
]
}
这篇关于禁用刷新/后退/前进在自己的浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!