www.webdeveloper.com
Results 1 to 5 of 5

Thread: how to do 'is not true' ?

  1. #1
    Join Date
    Nov 2005
    Location
    Bundanoon: first village to ban bottled water
    Posts
    214

    how to do 'is not true' ?

    I'm looking for a way to style first for certain browsers (Opera, Safari, Chrome), and then to direct other browsers (basically FF and IE) to a separate stylesheet.

    This would need something like
    Code:
    function cssAlt() {
       if('window.opera' != ??  && '@media screen and (-webkit-min-device-pixel-ratio:0)' != ?? {
    document.write('<link rel="stylesheet" type="text/css" href="_css/alt.css">')}
    }
    Apart form being uncertain about how to write "is false", it looks like it might need some variables declared first?

    Suggestions welcome...

  2. #2
    Join Date
    Mar 2010
    Posts
    2,803
    There are a few ways you can detect browser names.

    Maybe use this as a guide.

    All you would need to do is link the code below (from an external .js) in your <head> and then below this link in your <head>
    call setCSSforBrowser(cssPath) to set the appropriate stylesheet for your browser.

    The search strings in getBrowserName() are currently correct for their browsers. If you want to support other browsers, display their navigator.userAgent to see what browse name they are using.

    You would also need to add additional else-if blocks in setCSSforBrowser(cssPath) for the browsers not in the function.

    By default, the FF3 stylesheet is set for unsupported browsers.


    Code:
     
    /*******************************************************************
     This function returns the browser name as a string
    *******************************************************************/
    function getBrowserName()
    {
        var name = "Unknown";
        if(navigator.userAgent.indexOf("MSIE")!=-1) {
            name = "MSIE";
        } else if(navigator.userAgent.indexOf("Firefox")!=-1) {
            name = "Firefox";
        } else if(navigator.userAgent.indexOf("Opera")!=-1) {
            name = "Opera";
        } else if(navigator.userAgent.indexOf("Chrome") != -1) {
            name = "Chrome"; }
        else if(navigator.userAgent.indexOf("Safari")!=-1) {
            name = "Safari";
        }
        return name;   
    }
    var browserName   = getBrowserName();
      
    function setCSSforBrowser(cssPath)  {      
        if(browserName == "Firefox") {
            document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'FF3.css" />');
        } else if(browserName == "Safari") {
            document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'SAF.css" />');
        } else if(browserName == "Opera") {
            document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'OP.css" />');               
        } else {//we have an unsupported browser  - use the FF css and hope for the best !!!  
            document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'wpc_FF3.css" />');
        }
    }

  3. #3
    Join Date
    Aug 2007
    Posts
    3,767
    What CSS are you changing for Firefox? I find it strange that you would need an entire stylesheet for IE and Fx, when it's normally between IE and Opera/Chrome/Safari/Fx/basically everything else that the problems are. IE conditional comments are the best for detecting IE.
    Great wit and madness are near allied, and fine a line their bounds divide.

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by Declan1991 View Post
    What CSS are you changing for Firefox? I find it strange that you would need an entire stylesheet for IE and Fx, when it's normally between IE and Opera/Chrome/Safari/Fx/basically everything else that the problems are. IE conditional comments are the best for detecting IE.
    The problem is detailed here
    http://www.webdeveloper.com/forum/sh...d.php?t=232238

    I had the same position: I see no reason for Opera might need a specific CSS code. The OP problem seems rather related to the inappropriate way he uses the font types, font family, font size and measurement units.

  5. #5
    Join Date
    Nov 2005
    Location
    Bundanoon: first village to ban bottled water
    Posts
    214
    @ tirna
    thankyou, that is a valuable resource.
    @declan & Kor
    I've tied myself in knots with this one. See my reply to Kor's comment in the CSS forum: the solution is probably a better specification of serif fonts.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles