Web Analytics Made Easy -
StatCounter document.write - CSS? - CodingForum

Announcement

Collapse
No announcement yet.

document.write - CSS?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • document.write - CSS?

    I don´t understand anything? How did I do this, it works with N6 and IE 6, not testet with Opera. How can it be improved? My vison of this is that I write a page in very simple HTML and depending on browser type different CCS is used. Dont´t know much about javascript :-/
    <script type="text/javascript">
    var browser_type=navigator.appName
    var browser_version=parseInt(navigator.appVersion)

    if (browser_type=="Netscape"&&browser_version>=5){
    document.write('<link rel="stylesheet" type="text/css" href="css/index.css">');}
    else if (browser_type=="Microsoft Internet Explorer"&&browser_version>=4){
    document.write('<link rel="stylesheet" type="text/css" href="css/ie_index.css">');}
    else if (browser_type=="Opera"&&browser_version>=5){
    document.write('<link rel="stylesheet" type="text/css" href="css/opera_index.css">');}
    else
    window.location="http://ullvitorget.koping.se/~JTR/sorry.html"
    </script>

  • #2
    Well, I don't know hot to make it simpler but try this:
    var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1;
    var ns6=document.getElementById&&navigator.userAgent.indexOf("Opera")==-1;
    var ns4=document.layers;

    Now use :

    if(ie4) { document.write('.....'); }
    if(ns4) { document.write('.....'); }
    if(ns6) { document.write('.....'); }

    Scripting | JavaScripts | PerlScripts | Python Scripts | Articles | My Journal

    Comment

    Working...
    X