Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How can i include .css file by using java script based on the browser...?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to call two different style sheet depending on the browser from Java script....? I am trying to call it by putting the link tag in document.write() function... The Example code is as follows, but it is not working... Can any body tell me what function do i have to use....?

function abc()
{
if (navigator.appName == "Netscape")
{
document.write("<link rel='stylesheet' src='/discounting/discounting.css' href='/discounting/discounting.css' type='text/css'> ");
}
}

Thank You
Lakshmi.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well simply because it is too late to load the css file, the page has loaded before the script has executed, what you can try to do is
1) put the script inside the <head></head> tags and see if it works
2)calculate the target file name for the css in the parent frame (that defines the frames) and then in the current frame use the pre calculated filename to load the css file.
manav
 
manav k
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and also use ../ before your href
href='../discounting/discounting.css'
-manav
 
A magnificient life is loaded with tough challenges. En garde tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic