开发者

Can I remove font-size declarations from document with Javascript?

I want to make a Chrome extension (so decent & documented Javascript) that removes ALL font-size declarations from a document.

Document stylesheets:

document.styleSheets

Stylesheet rules:

document.styleSheets[0].rules

Rule declaration (or whatcha call em?):

document.styleSheets[0].rules[0].style.fontSize

How do I remove that last one? I want to use the browser's standards, so not set everyth开发者_如何学编程ing to 100%. Is there a way to remove all font-size styles?

(I don't care about inline styles or javascript added styles.)

BTW

Anybody know why .rules is empty (null) for the all.css stylesheet of Stack Overflow? There are a LOT of styles in there and Chrome uses them. Why can't I access them in document.styleSheets?


I don't think it's possible, because you can't access stylesheet rules loaded from another domain. This is a security restriction similar to AJAX same origin policy.


What about injecting custom css through manifest and overriding font sizes to default values:

* {font-size:1em !important;}
h1 {font-size:2em !important;}
h2 {font-size:1.5em !important;}
h3 {font-size:1.17em !important;}
h5 {font-size:.83em !important;}
h6 {font-size:.67em !important;}

User agent stylesheet doesn't declare sizes for many elements, mostly only for headers. I couldn't find exact default stylesheet for Chrome, but here is a few from other browsers, should be something very similar.


  1. Try setting it to nothing = ''
  2. Try setting it to null
  3. You can try the javascript delete function: http://www.openjs.com/articles/delete.php
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜