作者:手机用户2602938525 | 来源:互联网 | 2023-05-18 05:58
IsthereanywaytofetchtherawcontentsofaCSSfile?有没有办法获取CSS文件的原始内容?LetsimaginethatIwa
Is there any way to fetch the raw contents of a CSS file?
有没有办法获取CSS文件的原始内容?
Lets imagine that I wanted to fetch any vendor-specific css properties from a CSS file. I would need to somehow grab the CSS contents and parse them accordingly. Or I could just use the DOM to access the rules of a CSS file.
让我们想象一下,我想从CSS文件中获取任何特定于供应商的css属性。我需要以某种方式获取CSS内容并相应地解析它们。或者我可以使用DOM来访问CSS文件的规则。
The problem is that in while using the DOM, mostly all browsers (except for <= IE8) tend to strip out all of the custom properties that do not relate to their browser engine (webkit strips out -moz and -o and -ms). Therefore it wouldn't be possible to fetch the CSS contents.
问题在于,在使用DOM时,大多数浏览器(除了<= IE8)都倾向于删除与浏览器引擎无关的所有自定义属性(webkit剥离-moz和-o和-ms) 。因此,无法获取CSS内容。
If I were to use AJAX to fetch the contents of the CSS file, then if that CSS file hosted on another domain, then the same origin policy would break and the CSS contents could not be fetched.
如果我使用AJAX来获取CSS文件的内容,那么如果该CSS文件托管在另一个域上,那么相同的源策略将会中断并且无法获取CSS内容。
If one were to use a cross-domain AJAX approach then there would only be a JSONP solution which wouldn't work since we're not parsing any Javascript code (therefore there is no callback).
如果一个人使用跨域AJAX方法,那么只有JSONP解决方案不起作用,因为我们没有解析任何Javascript代码(因此没有回调)。
Is there any other way to fetch the contents?
有没有其他方法来获取内容?
3 个解决方案