Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Importing a css and js file when browser is NOT* IE

    I've seen this done but for the life of me i can't find the example.

    for obvious reasons document.write will not work. any suggestiongs or links to tutorials.

    I have not a clue on how to do this. i've thought about browser detection via PHP but thats just too buggy/unreliable.

    basically i have a .css and .js file that i want to include on the website ONLY when they are not using IE.

    I have 'generic' code for IE but the cutom display for my form elements does not work in IE, infact it breaks the elements in IE....
    Last edited by rlemon; 10-20-2005 at 03:25 PM.
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    How are you intending to identify that the browser is IE?

    What is the purpose of the non-IE code? Why doe you specifically need to single out that browser? Is there some particular functionality that identifies what you are trying to do that you can test for?

    In Javascript IE on windows can best be identified by testing for if activeX is supported but that would treat IE on the Mac as a non-IE browser.

    There are CSS hacks that allow code to be added that is specific to IE and IE-Mac.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall
    How are you intending to identify that the browser is IE?

    What is the purpose of the non-IE code? Why doe you specifically need to single out that browser? Is there some particular functionality that identifies what you are trying to do that you can test for?

    In Javascript IE on windows can best be identified by testing for if activeX is supported but that would treat IE on the Mac as a non-IE browser.

    There are CSS hacks that allow code to be added that is specific to IE and IE-Mac.
    As mentioned in my origional post i have code that does not work in IE.

    This is a added feature that is not needed ultimatly but does make the site look nice. I myself am not an IE user, and i plan on using the site so i wish to code it to those specs.
    This does not mean that i am totally ignorant of IE users. like i said i wish to only have this code included when the browser is not ie so everyone can still use the functionality of the site.

    So please, any constructive help would be appreciated.
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

  • #4
    gph
    gph is offline
    Regular Coder
    Join Date
    Apr 2005
    Posts
    161
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rlemon
    for obvious reasons document.write will not work. any suggestiongs or links to tutorials.
    Not that document.write is the best way to go but what do you mean by "will not work"?

    Code:
    if((!document.all||window.opera)&&document.getElementById)
    document.write('<script src="..." type="text/javascript"><\/script><link rel="stylesheet" type="text/css" href="...">)
    <edit>editing errors in code</edit>
    Last edited by gph; 10-20-2005 at 03:12 AM.

  • #5
    gph
    gph is offline
    Regular Coder
    Join Date
    Apr 2005
    Posts
    161
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by gph
    Not that document.write is the best way to go
    I was thinking that introducing the elements using the DOM would be better but that would require that it be done onload or after the <head>. Maybe document.write is the best way to go on the client.

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by rlemon
    I have 'generic' code for IE but the cutom display for my form elements does not work in IE, infact it breaks the elements in IE....
    If we solve this problem instead, then you won't need to exclude css and script in IE.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #7
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv
    If we solve this problem instead, then you won't need to exclude css and script in IE.
    this is not worth the effort.

    and document.write was not working. i was unable to get it working - don't know why.
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Can you elaborate on what's happening instead of just saying "it's not working"? Can you post the code?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #9
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Don't bother using either js object/browser detection or CSS hacks. Use conditional comments.

    e.g.
    Code:
    <!--[if IE]>
    
    <style type="text/css"> @import url(ie.css) </style>
    <script type="text/javascript" src="ie.js"></script>
    
    <![endif]-->

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by Bill Posters
    I also initially thought of that. But what rlemon wants is to include css and js when browser is NOT IE. Though in the thread title, it's the opposite. Unless there was a mistake in the content and not in the title.

    Title: Importing a css and js file when browser is IE
    Content:
    Quote Originally Posted by rlemon
    basically i have a .css and .js file that i want to include on the website ONLY when they are not using IE.
    Last edited by glenngv; 10-20-2005 at 09:37 AM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #11
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    My bad (and rlemon's)

  • #12
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Bill Posters
    My bad (and rlemon's)
    whooops!
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

  • #13
    New Coder
    Join Date
    Jan 2005
    Location
    Atlanta
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I agree with glenngv that, rather than looking for a hack to serve code to non-IE, the best thing to do is to examine what you have to see if you can make it work without a hack. That said, you could use the comment element. As far as I know, only IE supports it, though I have done NO research on this, and I very easily could be wrong. The usage would be:
    Code:
    <!--
    here is a comment that all browsers
    will regard as a comment
    -->
    <comment>
    here is a comment that IE will regard
    as a comment, but other browers will
    render the contents
    </comment>

  • #14
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jmccaskill
    I agree with glenngv that, rather than looking for a hack to serve code to non-IE, the best thing to do is to examine what you have to see if you can make it work without a hack. That said, you could use the comment element. As far as I know, only IE supports it, though I have done NO research on this, and I very easily could be wrong. The usage would be:
    Code:
    <!--
    here is a comment that all browsers
    will regard as a comment
    -->
    <comment>
    here is a comment that IE will regard
    as a comment, but other browers will
    render the contents
    </comment>

    thankyou and i will keep that in mind. however I have just recently given up on the code i wanted to run when the browser != IE

    The application is still not 100% (there is some issue with the height spacing of the footer bar) but here is the site:

    Edit: had posted url but removed it, the site is an image gallery and there are alot of personal images on it. the images are not all of me so i am unsure if everyone who is on the site wants this to become public (i'm making it for work - you know, a place to post images from company events.).
    Once i have replaced those images with some temporary images i will repost a link back to the image gallery.


    Take a look, see what you think.
    Last edited by rlemon; 10-20-2005 at 08:34 PM.
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

  • #15
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by jmccaskill
    I agree with glenngv that, rather than looking for a hack to serve code to non-IE, the best thing to do is to examine what you have to see if you can make it work without a hack. That said, you could use the comment element. As far as I know, only IE supports it, though I have done NO research on this, and I very easily could be wrong. The usage would be:
    Code:
    <!--
    here is a comment that all browsers
    will regard as a comment
    -->
    <comment>
    here is a comment that IE will regard
    as a comment, but other browers will
    render the contents
    </comment>
    I'm not sure introducing invalid, proprietory elements is the way to go.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •