2010-07-22 36 views
1

有没有办法在加载网站时执行一些JavaScript。 例如,我想隐藏Facebook聊天,并且想在加载网站时执行 document.getElementById('pagelet_chat_home')。style.display =“none”。Chrome和自动执行javascript函数

回答

4

您可以将所需的操作包装到一个greasmonkey脚本中 - Chrome支持开箱即用的greasemonkey用户脚本,并将它们自动转换为插件。

将以下内容另存为script.user.js并使用Chrome打开它。 Chrome应该将其检测为插件并进行安装。没有检查它是否真的有效,但应该没有问题。

// ==UserScript== 
// @name   Hide Pagelet 
// @namespace  hide_pagelet 
// @description An example Greasemonkey script that hides a pagelet 
// @include  http://*.facebook.com/* 
// ==/UserScript== 

document.getElementById('pagelet_chat_home').style.display = "none"; 
+0

谢谢。其他浏览器(IE,Firefox)呢?他们是否支持greasmonkey脚本或可以使用其他方式。 – Ilian 2010-07-22 16:37:51

+0

Firefox通过插件支持Greasemonkey脚本。 http://en.wikipedia.org/wiki/Greasemonkey – Andris 2010-07-22 17:06:22