使用Greasemonkey阻止网页内的弹出窗口JS脚本
例如网页内有如下内嵌弹出窗口脚本
<script language="JavaScript">
<!-- Begin
function popup() {
window.open('http://www.taobao.com','','');
window.focus();
}
// End -->
</script>
首先,安装Greasemonkey(参考http://www.firefox.net.cn/dig/toc/),到Firefox Add-ons官网 https://addons.mozilla.org,搜索Greasemonkey,点击安装。
然后,安装后重启Firefox,点击菜单栏中的“工具”--> "Greasemonkey" --> "New User Script...",创建一个新的GM脚本,在"New User Script..."对话框中:
Name: 给GM脚本取了名字,例如no_popup
Namespace: 无所谓,随便写几个字符串,一般是GM脚本的下载地址
Description: 无所谓,说明一下这个GM脚本的用处
Includes: 指定在哪些网页运行这个GM脚本,可以使用通配符,例如允许所有网页就是*,如果允许sohu.com就是http://*.sohu.com/*
Excludes: 指定不在哪些网页运行这个GM脚本,例如不在sina.com运行就是http://*.sina.com/*
点击OK后,进入GM脚本编辑,很简单只需要写入两行东西
unsafeWindow.popup = function () {
var sorryMsg = "This souldn't appear because Greasemonkey can divide by zero.";
};
上面2行可以简单的理解为替代网页中原来的popup函数。
那么整个GM脚本看上去是这样的:
// ==UserScript==
// @name no_popup
// @namespace localhost
// @description Replace the popup() function
// @include *
// @exclude http://*.sina.com/*
// ==/UserScript==
unsafeWindow.popup = function () {
var sorryMsg = "This souldn't appear because Greasemonkey can divide by zero.";
};
例如网页内有如下内嵌弹出窗口脚本
<script language="JavaScript">
<!-- Begin
function popup() {
window.open('http://www.taobao.com','','');
window.focus();
}
// End -->
</script>
首先,安装Greasemonkey(参考http://www.firefox.net.cn/dig/toc/),到Firefox Add-ons官网 https://addons.mozilla.org,搜索Greasemonkey,点击安装。
然后,安装后重启Firefox,点击菜单栏中的“工具”--> "Greasemonkey" --> "New User Script...",创建一个新的GM脚本,在"New User Script..."对话框中:
Name: 给GM脚本取了名字,例如no_popup
Namespace: 无所谓,随便写几个字符串,一般是GM脚本的下载地址
Description: 无所谓,说明一下这个GM脚本的用处
Includes: 指定在哪些网页运行这个GM脚本,可以使用通配符,例如允许所有网页就是*,如果允许sohu.com就是http://*.sohu.com/*
Excludes: 指定不在哪些网页运行这个GM脚本,例如不在sina.com运行就是http://*.sina.com/*
点击OK后,进入GM脚本编辑,很简单只需要写入两行东西
unsafeWindow.popup = function () {
var sorryMsg = "This souldn't appear because Greasemonkey can divide by zero.";
};
上面2行可以简单的理解为替代网页中原来的popup函数。
那么整个GM脚本看上去是这样的:
// ==UserScript==
// @name no_popup
// @namespace localhost
// @description Replace the popup() function
// @include *
// @exclude http://*.sina.com/*
// ==/UserScript==
unsafeWindow.popup = function () {
var sorryMsg = "This souldn't appear because Greasemonkey can divide by zero.";
};