473,770 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Possible to detect which stylesheet in use?

mar2195
1 New Member
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" after the <BODY> tag! (= cannot place this script in the <HEAD>)

EXAMPLE:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <link rel="stylesheet" href="main.css" type="text/css">
  4. </head>
  5. <body>
  6. blah, blah....
  7. <script> detectCurrentStylesheetBeingUsed() </script>
  8. </body>
  9. </html>
  10.  
My guess is that this cannot be done ... but I'd like to hear from others.


Thanks.
Nov 23 '06 #1
2 1612
Thevercad
26 New Member
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" after the <BODY> tag! (= cannot place this script in the <HEAD>)

EXAMPLE:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <link rel="stylesheet" href="main.css" type="text/css">
  4. </head>
  5. <body>
  6. blah, blah....
  7. <script> detectCurrentStylesheetBeingUsed() </script>
  8. </body>
  9. </html>
  10.  
My guess is that this cannot be done ... but I'd like to hear from others.


Thanks.

Of course, its possible. to detect which stylesheet is being used. Put the following code inside detectCurrentSt ylesheetBeingUs ed().

Expand|Select|Wrap|Line Numbers
  1. function detectCurrentStylesheetBeingUsed(){
  2.     var styleObj;
  3.     styleObj = document.getElementsByTagName("link");
  4.     if(styleObj.getAttribute("rel").indexOf("style") != -1){
  5.         alert(styleObj.href);
  6.     }
  7. }
I hope it works for you.
Nov 23 '06 #2
Thevercad
26 New Member
Please ignore my last post. The following code should work. Put the following code inside detectCurrentSt ylesheetBeingUs ed().

Expand|Select|Wrap|Line Numbers
  1. function detectCurrentStylesheetBeingUsed(){
  2.     var styleObj = document.getElementsByTagName("link");
  3.     var i=0;
  4.     while(styleObj[i]){
  5.         if(styleObj[i].getAttribute("rel").indexOf("style") != -1){
  6.             alert(styleObj[i].href);
  7.         }
  8.         i++;
  9.     }
  10. }
This will give you all the stylesheets that your html document is using. [/quote]
Nov 23 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2785
by: Ralf Wahner | last post by:
Dear Masters of XSLT Could I ask you for a clue on the following question? I'd like to use XSLT to transform an XML source file to LaTeX. In the following small example the <para> Element contains (I think so) - a text node (node one) - an element node (node two) - a text node (node three)
7
14543
by: Michael Hill | last post by:
I have a perl script that i use to render a html page. In that page i call out a stylesheet. If the user has a 800x600 display the fonts are really too big. Since screen resolution is a function of the client and I have this javascript ot detect the srecc size: function ck_res() { if ( (screen.width != 1024) && (screen.height != 768) ) {
2
1592
by: Sam | last post by:
Hi all I have a web page that allows user to referenced a stylesheet on my local network. Is there a way to detect the background color of this webpage? If I know the stylesheet that was used to set the background of my webpage, is there an easy way to know the property set for the "BACKGROUND-COLOR" of the body block
4
1872
by: KoRnDragon | last post by:
I'm using a script to detect which browser is using in order to include the correct stylesheet but on this one page (http://korndragon.com/ffa5.php) It thinks I'm using Internet Explorer when I'm really using FireFox. I have the same script included on all pages on my site and it's never messed up before. In fact It's included inside the nav, so nothing was changed. The script itself: http://korndragon.com/style.php (view source and you...
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.