/    Sign up×
Community /Pin to ProfileBookmark

Possible to detect which stylesheet in use?

Is it possible to use Javascript to detect which stylesheet is currently being used in a page?

… a script to detect the HREF value in the <link> tag which is located in the <HEAD> of the page.

IMPORTANT:
I need to place this javascript “detect” [B]after[/B] the <BODY> tag! (= cannot place this script in the <HEAD>)

EXAMPLE:

[CODE]
<html>
<head>
<link rel=”stylesheet” href=”main.css” type=”text/css”>
</head>
<body>
blah, blah….
<script> detectCurrentStylesheetBeingUsed() </script>
</body>
</html>
[/CODE]

My guess is that this cannot be done … but I’d like to hear from others.

Thanks.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERNov 23.2006 — Clarification please:

Are you trying to detect if a stylesheet is being use on a page you did not create?

Or are you trying to detect which of several stylesheets are begin used in a page you created?
Copy linkTweet thisAlerts:
@mjdamatoNov 23.2006 — If you give the link tag an id, you can reference the src of the element & you should be able to chage the style sheet ont he fly. I have used the same logic to change the src for a script include tag so I could dynamically change a set of data through js.
Copy linkTweet thisAlerts:
@hyperliskNov 23.2006 — You can do anything with JavaScript as long as you are good enough...
Copy linkTweet thisAlerts:
@mar2195authorNov 23.2006 — I am working on a web page that I am being "fed" that I have no control over. I cannot add an "id" to the <LINK> tag ... or anything else.

Meaning... I am able to manipulate/edit the page within the <BODY> section only.

So... I need to DETECT which Stylesheet is specifically being used within the <LINK> tag.

There are a few different stylesheets that are being used. I need to know which stylesheet is the CURRENT one so that I can [I]counter-code[/I] (if that's a real word ? ) specific font colors, background colors, etc.

If you need futher explanation, I'll be happy to give deeper descriptions. But I think that I've covered the situation.

Thanks.
Copy linkTweet thisAlerts:
@mjdamatoNov 23.2006 — This sample code should help. It will search for any link tags and if the tag is a stylesheet will alert the href.
<i>
</i> links = document.getElementsByTagName('link')
for (i=0; i&lt;links.length; i++) {
if (links[i].rel == "stylesheet") {alert(links[i].href)}
}
×

Success!

Help @mar2195 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...