Welcome to Dream.In.Code
Getting Help is Easy!

Join 109,553 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,293 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Browser Detecting using document.styleSheets

 
Reply to this topicStart new topic

Browser Detecting using document.styleSheets

Moshambi
post 4 Aug, 2008 - 04:28 PM
Post #1


New D.I.C Head

*
Joined: 20 Nov, 2007
Posts: 34


My Contributions


ok so what im trying to do here is to check if it is IE and if it is then enable the IE Specific style sheet and disable the default one and vice versa(the else part of the if).

for some reason it is working when i test it in firefox but it will not work when i do it in IE...i dont know if maybe its the version i am running (which is 6) but any help would be greatly appreciated. Thank you in advance.

Here is my code:


CODE

function detect()
{
    var isIE = (navigator.appName == "Microsoft Internet Explorer");
    
    if(isIE)
    {
      document.styleSheets[0].disabled = true;
      document.styleSheets[1].disabled = false;  
  }
  else
  {
      document.styleSheets[0].disabled = false;
      document.styleSheets[1].disabled = true;
  }
}
User is offlineProfile CardPM

Go to the top of the page


Martyr2
post 4 Aug, 2008 - 06:30 PM
Post #2


Programming Theoretician

Group Icon
Joined: 18 Apr, 2007
Posts: 4,365



Thanked 83 times

Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions


First make sure that you have stylesheets linked using the <link> tag in the heading and then for IE the syntax is using parenthesis and not brackets...

CODE

document.styleSheets(0).disabled = true;


Notice here that we are using parenthesis around the number and not a bracket. IE treats it as an array in the style of like VBscript.

This should fix your problem.

"At DIC we be styleSheet tossing code ninjas... toss one in, toss one out, toss one in and shake that styleSheet all about, you do the hokey pokey and turn yourself around and that is what it is all about!" decap.gif
User is online!Profile CardPM

Go to the top of the page

Moshambi
post 4 Aug, 2008 - 08:04 PM
Post #3


New D.I.C Head

*
Joined: 20 Nov, 2007
Posts: 34


My Contributions


oh thank you very much man. you are genius! ha stupid microsoft...why cant they just be like mozilla =/ but thanks again that worked perfectly as you might have already known
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 9/7/08 10:48PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month