简体   繁体   中英

Get stylesheet text from <link> tag

i've got a sylesheet <link> tag:

<link rel=stylesheet href="/path/to/foo/bar.css" />

and i'd like to get the text of the /path/to/foo/bar.css stylesheet via javascript.

is this possible? i'll even accept answers that don't work cross-browser...

NOTE: answers involving document.styleSheet don't count, since the browser will have already transformed stuff like URL's, and i'm interested in the original source (even though this does provide an interesting way to resolve URLs... )

ASLO NOTE: i'd prefer to do this w/o any xhr's

Simply do an AJAX request to the specified URL.

Using jQuery:

$.get('/path/to/foo/bar.css', function(CSS_text) {
    // Just use the CSS_text here...
});

You can easily do the same with native JS...

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM