Chrome扩展程序 - 用于在任何页面上运行js的简单内容脚本 [英] Chrome Extension - Simple Content Script for running js on any page
问题描述
Chrome扩展程序 - 内容脚本 - 我如何编写一个简单的内容脚本,在每个页面上执行JavaScript警报(hello)加载..我的意思是当我去google.com等一些页面时,信息应该出现..或者如果我重新加载任何页面,消息应该出现在我newvbiew。请帮助。
我到目前为止拥有此json文件
{
name:突出显示一些短语,
description:在页面加载后从websql数据库中高亮一些预定义的文本,
version:0.1,
权限:[
标签,< all_urls>
,
browser_action:{
default_icon:icon.png,
default_popup:popup.html
},
$ b $content_scripts:[
{
matches:[
http:// * / *,
https:// * / *
,
js:[content.js]
}
],
背景: {
page:background.html
},
manifest_version:2
}
如果您只需提醒 hello
下面是一个简单的演示:
Manifest.json
:
{
name:突出显示某些短语,
description:高亮显示来自websql数据库的一些预定义文本加载,
版本:0.1,
权限:[
tabs,< all_urls>
,
browser_action:{
default_icon:icon.png
},
content_scripts:[
{
matches:[
http:// * / *,
https:// * / *
],
js :[content.js],
run_at:document_end//关注这一行
}
],
manifest_version:2
$ / code>
以下是 content.js $ c
// alert(hello); $ c>:
document.body.style.background ='yellow';
是的,这已经足够。
当然,不要忘记添加一个名为 icon.png
的图标与这两个文件位于同一目录。
然后在您的Chrome中测试它。
Chrome Extension - Content Script - How can i write a simple content script that will execute a javascript like alert ("hello") on every page loads.. I mean when i go to some pages like google.com the message should appear.. or if i reload any page, the message should appear Im newvbiew. pls help.
i so far have this json file
{
"name": "Highlight some phrases",
"description": "Hightlight some pre defined text from websql database after page loads",
"version": "0.1",
"permissions": [
"tabs","<all_urls>"
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": [
"http://*/*",
"https://*/*"
],
"js": ["content.js"]
}
],
"background": {
"page": "background.html"
},
"manifest_version": 2
}
If all you need is to alert a hello
on every page loaded, below is a simple demo:
Manifest.json
:
{
"name": "Highlight some phrases",
"description": "Hightlight some pre defined text from websql database after page loads",
"version": "0.1",
"permissions": [
"tabs","<all_urls>"
],
"browser_action": {
"default_icon": "icon.png"
},
"content_scripts": [
{
"matches": [
"http://*/*",
"https://*/*"
],
"js": ["content.js"],
"run_at": "document_end" // pay attention to this line
}
],
"manifest_version":2
}
and here is what in content.js
:
// alert("hello");
document.body.style.background = 'yellow';
Yes, that's enough.
And of course don't forget to add an icon named icon.png
at the same directory with these two files.
Then test it in your chrome.
这篇关于Chrome扩展程序 - 用于在任何页面上运行js的简单内容脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!