By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,689 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,689 IT Pros & Developers. It's quick & easy.

Get file name from STYLE tag

P: n/a
If I have this in the HEAD of a page:

<style type="text/css">@import url(scripts/foo.css);</style>

can can I get the name of the CSS file (in this case its "foo")?
Andrew Poulos
Feb 10 '07 #1
Share this Question
Share on Google+
1 Reply

P: n/a
On Feb 9, 6:59 pm, Andrew Poulos <ap_p...@hotmail.comwrote:
If I have this in the HEAD of a page:

<style type="text/css">@import url(scripts/foo.css);</style>

can can I get the name of the CSS file (in this case its "foo")?

Andrew Poulos
<style type="text/css">
@import url(scripts/foo.css);
@import url(scripts/bar.css);
@import url(scripts/bats.css);
</style>
<script type="text/javascript">
var styles = document.getElementsByTagName('style'),
names = [],
matches;

for (var i=0, nstyles=styles.length; i<nstyles; i++) {
// find lines with an @import directive
matches = styles[i].innerHTML.match(/@import url\(.*\);?/mg);
for (var j=0, nmatches=matches.length; j<nmatches; j++) {
// extract content from parens
names[names.length] = matches[j].match(/\((.*)\)/)[1];
}
}

// names array now contains the names of your stylesheets
alert(names);
</script>

-David

Feb 10 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.