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
    TrainReq
    Guest

    Cecking browser type

    How do I get it to where it more/less says

    If the browser is IE , than run the following function

    if(st.length > 2083) st = st.substr(0, 2083);

    And If the browser is not IE, than dont run that above function

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,899
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    if (document.all) {
    if (st.length > 2083) {st = st.substr(0, 2083)} // length of substring to be returned
    }

  • #3
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by Philip M View Post
    if (document.all) {
    if (st.length > 2083) {st = st.substr(0, 2083)} // length of substring to be returned
    }
    Could you explain the connection between the presence of document.all and the browser being I.E.?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,899
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Microsoft's Internet Explorer has a proprietary property of the document object that is called "all".
    if (document.all) {
    tests whether this property is present. In other words, whether the browser is IE4+.

    For more info see:-

    http://www.javascriptkit.com/javatut...jdetect3.shtml
    Last edited by Philip M; 06-13-2007 at 01:14 PM. Reason: Added reference

  • #5
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by Philip M View Post
    Microsoft's Internet Explorer has a proprietary property of the document object that is called "all".
    if (document.all) {
    tests whether this property is present. In other words, whether the browser is IE4+.

    For more info see:-

    http://www.javascriptkit.com/javatut...jdetect3.shtml
    It's wrong/out of date, just like so many of the scripts available there. The presence of document.all does not identify Internet Exporer.
    Try typing this into Opera's address bar: javascript:alert(document.all)

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,899
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by Arty Effem View Post
    It's wrong/out of date, just like so many of the scripts available there. The presence of document.all does not identify Internet Exporer.
    Try typing this into Opera's address bar: javascript:alert(document.all)
    Oooooooooooooo!
    Well how about:-

    if ((document.all) && (!window.opera)) {
    if (st.length > 2083) {st = st.substr(0, 2083)} // length of substring to be returned
    }

  • #7
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by Philip M View Post
    Oooooooooooooo!
    Well how about:-

    if ((document.all) && (!window.opera)) {
    if (st.length > 2083) {st = st.substr(0, 2083)} // length of substring to be returned
    }
    That will test true for FX in quirks mode. Try Googling "support document.all"

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,899
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by Arty Effem View Post
    That will test true for FX in quirks mode. Try Googling "support document.all"
    As I understand it quirks mode exists solely to facilitate backwards compatibility. New documents ought not to rely on quirks mode but should comply with standards mode.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

    In fact I do not know anyone who uses Opera which has about 1.5% of the market, about the same as IE5. Also, does Trainreq want his script to work solely in IE, or in browsers which mimic IE as well.

    However, it looks as though the problem can be overcome with a further tweak:-

    if ((document.all) && (!window.opera) && (!window.getComputedStyle)) { //IE, not Opera, not Firefox
    if (st.length > 2083) {st = st.substr(0, 2083)} // substring to be returned
    }
    Last edited by Philip M; 06-13-2007 at 05:29 PM.

  • #9
    TrainReq
    Guest
    will this work with IE6 and 7 .. cause i would like to say . If IE6 or IE7 , but not firefox or opera , do the function.

  • #10
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by TrainReq View Post
    will this work with IE6 and 7 .. cause i would like to say . If IE6 or IE7 , but not firefox or opera , do the function.
    The proper answer to this question is a question: What makes you think you need to do this? If you're trying to run code that won't be supported, you need to show it.

  • #11
    TrainReq
    Guest
    long story why.. but I need to get it to where the code only runs if it is IE6 or 7

  • #12
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 249 Times in 245 Posts
    I'm guessing it's for the maximum URL length for IE which is 2083. Other browsers has longer limit.

    I think conditional compilation of jscript in IE is the most suitable solution for this problem.

  • #13
    TrainReq
    Guest
    i dont get it. This is what i need to do ..

    If IE version is IE6 or IE7 , run the function , if it is not IE6 or IE7 (like IE5 and down or firefox or opera) than dont run the function.

  • #14
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,593
    Thanks
    0
    Thanked 645 Times in 635 Posts
    To test for IE you can test if the browser is running JScript rather than JavaScript (since IE runs JScript and other browsers run JavaScript). The following conditional code is treated as a comment in JavaScript but runs in IE.

    Code:
    /*@cc_on
       @if (@_jscript) 
    alert('browser is Internet Explorer');
       @end @*/
    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.

  • #15
    TrainReq
    Guest
    what about this


    Code:
    var browserName=navigator.appName; 
    
     if (browserName=="Microsoft Internet Explorer")
     {
      if(str.length > 298) st = str.substr(0, 298);
     }
    does that look right.. because if i go
    Code:
    var browserName=navigator.appName; 
    
     if (browserName=="Microsoft Internet Explorer")
     {
      alerts('you are using IE') 
     }


    It works just fine and only alerts me in IE .. but my question is.. did i throw if(str.length > 298) st = str.substr(0, 298); in the right place.
    Last edited by TrainReq; 06-14-2007 at 04:12 AM.


  •  
    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
    •