Monday, May 20, 2024
141
rated 0 times [  142] [ 1]  / answers: 1 / hits: 74544  / 12 Years ago, fri, december 28, 2012, 12:00:00

How can I add some HTML code to the loaded page if page's title contains specific text?



Chrome extensions are new grounds to me and your help would be greatly appreciated.


More From » google-chrome

 Answers
67

References:





You can take the following code as a reference for adding some HTML Code.



manifest.json



This file registers content script to extension.



{
name:Inject DOM,
description:http://stackoverflow.com/questions/14068879,
version:1,
manifest_version:2,
content_scripts: [
{
matches: [http://www.google.co.in/*,https://www.google.co.in/*],
js: [myscript.js]
}
]
}


myscript.js



A trivial script for adding a button to Google page



// Checking page title
if (document.title.indexOf(Google) != -1) {
//Creating Elements
var btn = document.createElement(BUTTON)
var t = document.createTextNode(CLICK ME);
btn.appendChild(t);
//Appending to DOM
document.body.appendChild(btn);
}


Output



You see a button added to a desired page



enter


[#81190] Wednesday, December 26, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sidneyh

Total Points: 118
Total Questions: 108
Total Answers: 105

Location: Mali
Member since Fri, Jun 18, 2021
3 Years ago
sidneyh questions
Tue, Jun 7, 22, 00:00, 2 Years ago
Wed, Apr 13, 22, 00:00, 2 Years ago
Wed, Aug 12, 20, 00:00, 4 Years ago
Wed, Jun 3, 20, 00:00, 4 Years ago
Fri, Apr 24, 20, 00:00, 4 Years ago
;