Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: how to ??

  1. #1
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to ??

    how to browser detect using javascript and/or php so that if my browser is IE this:
    HTML Code:
    <select name="dynamicselector2" size="2" onChange="generateimage(this.options[this.selectedIndex].value)">
    will look like
    HTML Code:
    size="1"
    and if my browser is not IE
    HTML Code:
    size="2"
    tnx :P

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Style your element with CSS.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    how do i do that? :P from what i understand of CSS its still somewhat static. if m using IE i will change the size in the CSS by 1 and if m using other browsers that is not IE i will change the size in the CSS by 2 :P can't i do it dynamically? something like if browser = IE then size = 1 else size = 2.

    i know the logic but not how to put it into script itself

  4. #4
    Join Date
    Jun 2006
    Posts
    182
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default

    PHP could be something like that:
    Code:
    size="<?php echo strstr($_SERVER["HTTP_USER_AGENT"], "MSIE") != false ? "1" : "2"; ?>"

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    i know the logic but not how to put it into script itself
    Easiest way to implement this here is the !important bug.

    !important ought to cause any rules that would override the rule it's applied to to be ignored, unless they are also !important. However, IE ignores it, so we can do things like this:
    Code:
    select {
      height: 1.2em !important;
      height: 2.4em;
    }
    DimX: There are two problems with your code. Firstly, you've got the 1 and the 2 completely the wrong way around. Secondly, strstr() can return 0, which will evaluate as false when using type-converting comparison (== and !=) and thus give you an incorrect result. Instead, you must use strict comparison (=== and !==), which will not perform type conversion.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Twey: ur script ddnt solve exactly my problem :P DimX's script solves it exactly with !== or != i dont see the difference

    tnx for the help guyz

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    DimX's script solves it exactly with !== or != i dont see the difference
    I explained the difference above
    Twey: ur script ddnt solve exactly my problem
    It was an example
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    even if i use the !== or the !=, the result that im aiming for is still the same :P
    this is what i meant by i dont see the difference

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Ah, but if "MSIE" appears at the beginning of the UA string, then using !=, that script will detect the browser as not being IE

    Plus, the user agent string is not necessarily a reliable indicator of the browser. If you looked for "Mozilla," for example, you'd find it in every IE browser's UA string since IE3, I think. Also, some browsers (and firewalls, and a couple of pieces of malware) change or strip the User-Agent header, user intervention aside.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    tnx for the 411

Bookmarks

Posting Permissions

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