3

My Chrome extension uses chrome.tabs.insertCSS method for modifying page styles. Sometimes I need to turn modifications off, is there way to do it without page reloading?

I know one way to do it: inject script with chrome.tabs.executeScript instead which then creates style element. Then I can cancel modification by removing inserted style element.

But may be there is more direct solution.

kriomant
  • 2,216
  • 1
  • 16
  • 21
  • 1
    Check out a solution I suggested here: http://stackoverflow.com/questions/18533820/how-do-i-remove-an-injected-css-file/18537071#18537071 TL;DR wrap your in `body.customclassname` and toggle that class name on `body` through JavaScript. – Timothée Boucher Sep 09 '13 at 14:37
  • 1
    The above should read "wrap your **styles** in `body.customclassname`". – Timothée Boucher Sep 09 '13 at 16:02
  • Ok, I understand your solution, thanks. However, it requires JavaScript to set body class. And if I inject JavaScript then I'd better just create style node.But I can use `body:not(.disabled-custom-style)` to avoid injecting JavaScript until it is required to disable style. – kriomant Sep 10 '13 at 01:39
  • Yes, you're right. Either way you'll need some JavaScript. (you might be able to insert CSS that cancels the first one, but that would be hard if not impossible for that to work on any random page) What I like with my solution is that once the CSS is inserted in the page, the toggling requires minimal code. Adding and removing a ` – Timothée Boucher Sep 10 '13 at 05:24

0 Answers0