Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Posts
    345
    Rep Power
    14
    Hi groundscape thanks for your contribution, right almost got it now.

    You are right the JavaScript syntax was wrong.
    I read it 3 times on 3 different weblogs. The first suggested you way you have wrote it but it didn't work.

    The second way suggested the way I put it, again it didn't work -
    www.santosj.name/projects/javascript-opacity-object/

    I just doubled checked it after you mentioned it and came across the W3C way of doing it.
    http://www.w3schools.com/css/css_image_transparency.asp
    PHP Code:
    document.getElementById("light").filters.alpha.opacity=10
    Now TBH I read this wrong and instead wrote this in my code-
    PHP Code:
    document.getElementById("light").style.filters.alpha.opacity=10
    Now my way with the error does actually work and the opacity is applied in Internet Explorer. However this does not work due to the fact that there is a syntax error and the next page is loaded instead, rather than just returning, but before it loads in Internet Explorer you can see that the div does have opacity applied to it.

    Now if I write it as the W3C suggests and leave out the style, Internet Explorer doesn't load the Ajax function and the div is still a solid blue.

    FireFox brings up an error saying -
    document.getElementById("light").style.filters is undefined.
    Now TBH honest getting it to work this way in FF isn't an issue because if I can get this to now work in IE I will just split the code for IE and get rid of the issue.

    Do you have any idea where to go now with IE as IE JavaScript is not my bag TBH and I reckon this is a bug rather than a feature?

    Thank you for your time especially on a Sunday

    Jaz
    Last edited by jazajay; August 25th, 2008 at 12:40 PM.
  2. #17
  3. Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2001
    Location
    Right now? On my chair.
    Posts
    1,795
    Rep Power
    254
    Just detect if the browser is IE and then execute that code.

    javascript Code:
     
       <SCRIPT type="text/javascript">
    // This function returns Internet Explorer's major version number,
       // or 0 for others. It works by finding the "MSIE " string and
       // extracting the version number following the space, up to the decimal
       // point, ignoring the minor version number
       function msieversion()
       {
          var ua = window.navigator.userAgent
          var msie = ua.indexOf ( "MSIE " )
     
          if ( msie > 0 )      // If Internet Explorer, return version number
             return parseInt (ua.substring (msie+5, ua.indexOf (".", msie )))
          else                 // If another browser, return 0
             return 0
     
       }
       </SCRIPT>
    Use markup the semantic way. You wouldn't want your dog answering the phone for you, would you?
    HTML Validator || CSS Validator -- HTML / CSS Main forums. JavaScript and PHP...maybe
    Bones: HTML; Skin: CSS; Muscle: JavaScript; Brains: PHP; Memory: MySQL
  4. #18
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Posts
    345
    Rep Power
    14
    Hi groundscape.
    Thanks for the code I would rather use Server side detection that way only code for the appropriate browser is loaded and useless code is admitted and the file is therefore smaller. But thank you for the code none the less.

    Now TBH I have not written JavaScript for a month or so and forgot all about the try catch statement.

    I have now added it and yes the opacity is added fully but IE brings up this message -
    'document.getElementById("light").style.filters.alpha' is null or not an object.
    Since adding the try catch I have added both of these to the css sheet on different occasions.
    PHP Code:
    filter:alpha(opacity=100)
    filter:progid:DXImageTransform.Microsoft.Alpha(opacity=100
    However the opacity has been applied but the page doesn't stay for more than a few seconds before the next page is loaded due to this error.

    Any idea on how I can fix this?
    Last edited by jazajay; August 25th, 2008 at 12:55 PM.
  6. #19
  7. /*
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    729
    Rep Power
    620
    Originally Posted by groundscape
    Isn't that JavaScript supposed to be
    Code:
    document.getElementById("light").style.="filter:alpha(opacity=20)";
    No ...each style property needs to be referenced explicitly.

    css Code:
    document.getElementById(some_id).style.JS_property_reference = "new_CSS_property_value";


    This site lists how the properties should be called.
    */
  8. #20
  9. Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2001
    Location
    Right now? On my chair.
    Posts
    1,795
    Rep Power
    254
    Try that...sorry my JavaScript isn't quite up to derelicts' abilities. Do you have an error page?
    [quote]However the opacity has been applied but the page doesn't stay for more than a few seconds before the next page is loaded due to this error.

    You have some sort of header?

    You can't use PHP to detect the browser type...well you probably can find out but JavaScript is the only way I know how.
    Use markup the semantic way. You wouldn't want your dog answering the phone for you, would you?
    HTML Validator || CSS Validator -- HTML / CSS Main forums. JavaScript and PHP...maybe
    Bones: HTML; Skin: CSS; Muscle: JavaScript; Brains: PHP; Memory: MySQL
  10. #21
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Posts
    345
    Rep Power
    14
    Heres how I do it server side.
    You parse the user agent for the browser type, version and if you want operating system, then write IF statements that are executed when the right browser comes along giving server specific code -

    Heres my browserselect.php file if you are interested.
    PHP Code:
    <?php
    $d 
    detect();
    $b $d['browser'];
    @
    $v $d['version'];
    $o $d['os'];
    function 
    detect()

      
    $browser = array ("IE","Opera","MOZILLA","NETSCAPE","FIREFOX","SAFARI");
      
    $os = array ("WIN","MAC","LINUX");
      
    $info['browser'] = "OTHER";
      
    $info['os'] = "OTHER";
      foreach(
    $browser as $parent)
      {
           
    $s strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $parent);
        
    $f $s strlen($parent);
        
    $version substr($_SERVER['HTTP_USER_AGENT'], $f5);
        
    $version preg_replace('/[^0-9,.]/','',$version);
        if(
    $s)
        {
             
    $info['browser'] = $parent;
            
    $info['version'] = $version;
        } 
      }
      foreach(
    $os as $val)
      {
           if(
    eregi($val,strtoupper($_SERVER['HTTP_USER_AGENT'])))
            
    $info['os'] = $val;
      } return 
    $info
    }
    if(
    eregi("opera",$_SERVER['HTTP_USER_AGENT']))
    {
     
    $b "Opera";
    }
    ?>
    Then you save the js file as a php file and send a php header which "tricks" the browser into thinking it is a .js file. But this allows you to write php code in your JS sheet, set PHP variables, browser detect etc...

    It's probably not conventional and TBH I only use it in the js file if it is a rare issue like this one where i need to give certain code to IE. I don't see why my other users should wait for the extra file size to download when I'm trying to circumvent an IE bug or something not supported yet in IE.

    Jaz
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo