Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7651429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:30:14+00:00 2026-05-31T11:30:14+00:00

I use this code below to load CSS files. var i, a; for(i=0; (a

  • 0

I use this code below to load CSS files.

var i, a;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++){
    if(a.getAttribute("title") == description){
        a.disabled = false;
        if(document.createStyleSheet) {
            try { document.createStyleSheet(a.href); } catch (e) {}
        }
        else {
        alert(a.href);
            var css;
            css         = document.createElement('link');
            css.rel     = 'stylesheet';
            css.type    = 'text/css';
            css.media   = "all";
            css.href    = a.href;
            document.getElementsByTagName("head")[0].appendChild(css);
        }
    }
    else if(a.getAttribute("title") != "default"){a.disabled = true;}
    }

Any reason why this should fail on Safari but works on IE, Chrome and Firefox??

Added:

I’m using:

    <script type="text/javascript">
        $(document).ready(function(){dynamicLayout();})
        $(window).resize(function() {dynamicLayout();})
    </script>

to call dynamicLayout,

and when changing the width of the viewport (safari browser window) it just refuses to switch to the right css file. But works fine in mozilla/ie/chrome….

Sooo, don’t know whats going on here. I always get trouble with jsfiddle for some reason, doesn’t want to save and sometimes crashes my browser :-/ so sorry about that..

Hope this helps, if not just keep asking and I’ll provide as much info as possible! =]

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:30:16+00:00Added an answer on May 31, 2026 at 11:30 am
    function dynamicLayout(){
    var winWidth = $(window).width();
    var winHeight = $(window).height();
    
    
    changeLayout("default");
    
    if (winWidth < 1148){
        changeLayout("thin");
    }
    if (winHeight < 810){
        changeLayout("tiny");
    }
    if ((winWidth < 1148) && (winHeight < 810)){
        changeLayout("thintiny");
    }
    

    }

    function changeLayout(description){
    var i, a;

    for(i=0; (a = document.getElementsByTagName(“link”)[i]); i++){
    if(a.getAttribute(“title”) == description){

            a.disabled = false;
            if(document.createStyleSheet) {
                try {document.createStyleSheet(a.href); } catch (e) {}
            }
    
            else {
    
                var css;
                css         = document.createElement('link');
                css.rel     = 'stylesheet';
                css.type    = 'text/css';
                css.media   = "all";
                css.href    = a.href;
                document.getElementsByTagName("head")[0].appendChild(css);
            }
        }
    
        else {
            if( (a.getAttribute("title") != "default") &&
                (a.getAttribute("title") != description)) {
    
                a.disabled = true;
            }
        }
    

    }
    }

    Code above works great.

    Turns out, Safari 5.something had a bug in it which made it impossible to insert css the way using script above. New version came out couple of days ago and now it’s working fine =]..

    Hope this helps anyone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try use below code to load an URL. URL url = new URL(urlstr);
I'm using the code below and also seen in this fiddle http://jsfiddle.net/peter/Xt5qu/ to use
I have an issue with this jquery code below. Please give me advice or
I would like to use the code below as a helper function, since it
UPDATE: I've posted the Renderer code below, since this code here doesn't seem to
Hi i am trying to load XML document and populate few checkboxlist. I use
I use the code bellow to dynamically include a CSS file: HtmlHead head =
I'm using the code below to load a text file content into a WebView
I am trying to use this code to define the APIs that are needed
when i use this code,the jquery code in the #paylasimlar does not run.i search

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.