lundi 27 octobre 2014

add class to tabbed page from chrome extension


Vote count:

0




I am developing a chrome extension which select a class from pop up list and apply it to open page in that active tab. and what i found is that in code parameter of chrome.tabs.executeScript


popup.js



function click(e) {
// console.log(e.target.className);
chrome.tabs.executeScript(null, {
// code : "document.body.style.backgroundColor='red'"
code : "var scriptOptions = {param1:'value1',param2:'value2'};"}, function(e){
console.log('clicked class');
console.info(e.target.className);
document.body.setAttribute('class', e.target.className);
});
window.close();
}




  • What is the way to add more than one line of code in code value? document.body.style.backgroundColor='colorname/colorcode' will change the background color but I need to change dynamically by adding class name with body




  • How to get e.target.className inside function if i use core javascrip ?




  • If I use jquery. it changed the that popup background color only, see code



    $(function(){
    console.log('jQuery added');
    $(document).on ('click', 'li', function(){
    console.log('on clicked');
    var cl = this.className;
    console.log(cl);
    $('body').removeClass().addClass(cl);
    });


    });





asked 1 min ago

diEcho

22.8k






add class to tabbed page from chrome extension

Aucun commentaire:

Enregistrer un commentaire