I want to associate some actions with keys (of a keyboard) and then modify the contents of a webpage loaded in the browser. For example, I'll write a firefox plugin and that would be listening to some keyboard events. Based on a key press (or something like that) I want to modify the html code of the page. For example, I would like to change the color of a link. Any suggestions on how can I go about doing this?
I think follwing sites will be helpfull on has dom reference and next has event examples, https://developer.mozilla.org/en/Gecko_DOM_Reference http://www.w3schools.com/JS/js_examples_3.asp
You can read the elements in the page using follwing methods,
1. getElementById 2. getElementsByTagName 3. getElementByName
and using the DOM you can play with it. ex
//change the background of text box to red var ele = document.getElementById('textBox1') ele.style.background = "red";
Install the Greasemonkey extension. You will need to read a lot of reference material.
在developer.mozilla.org上查看从chrome安全访问内容DOM
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.