But it HAS to be dynamic...



  • Had to wade through some bad CBT at work the other day, nothing special; but some of the things the 'quiz' was doing made me poke around at the source code. Again, nothing too interesting till I spotted this interesting bit of browser checking...

    (code from include file and actual page combined here for convenience; line breaks added)

    function BrowserProps() {
      var name = navigator.appName
      
      if (name=="Netscape") name = "ns"
      else if (name=="Microsoft Internet Explorer") name = "ie"
      
      this.v = parseInt(navigator.appVersion)
      this.ns = (name=="ns" && this.v>=4)
      this.ns4 = (this.ns && this.v==4)
      this.ns5 = (this.ns && this.v==5)
      this.nsMac = (this.ns && navigator.platform.indexOf("Mac") >= 0 )
      this.ie = (name=="ie" && this.v>=4)
      this.ie5 = (this.ie && navigator.appVersion.indexOf('MSIE 5')>0)
      this.ieMac = (this.ie && navigator.platform.indexOf("Mac") >= 0 )
      this.min = (this.ns||this.ie)
    }
    
    is = new BrowserProps()
    
    if( !is.min )
        document.write( 'Your browser does not support dynamic html. Please download a current version '+
         'of either Microsoft Internet Explorer or '+
         'Netscape Navigator  and try visiting our site again.  '+
         'Thank You.

    ' )

    I don't have a broswer old enough to test this, but it does seem to be trying to determine if it can use things like, oh... "document.write()"



  • This used to be pretty standard boilerplate for determining whether a browser supported DHTML. (In fact, it looks like it came straight out of Microsoft Press book on DHTML I used to own.) I don't see a WTF here.

    Note: Don't confuse DHTML support with JavaScript support. Several browsers had JavaScript support before DHTML came along.



  • You mean you don't want your website to support an early version NSCA Mosaic?  For shame!



  • Guess it was just the wording that through me then. In my mind, "dynamic HTML" included JS writing new content to the page, as the error message was doing. Again, couldn't test it; but it just looked "wrong".



  • @BlueKnot said:

    Guess it was just the wording that through me then. In my mind, "dynamic HTML" included JS writing new content to the page, as the error message was doing. Again, couldn't test it; but it just looked "wrong".

    That's because it pretty much IS just "wrong"

    if(!document.write) { alert ("Oh noes! Time warp to 1997!"); }


  • @Volmarias said:

    @BlueKnot said:
    ...but it just looked "wrong".

    That's because it pretty much IS just "wrong"

    if(!document.write) { alert ("Oh noes! Time warp to 1997!"); }

    Amen to that! DHTML had to wait until the version 4 browsers died out to become practical.



  •  Good thing they checked for Netscape 5.  That one is a pain to write code for.



  • @dgvid said:

    Several browsers had JavaScript support before DHTML came along.

    And this pre-DHTML javascript did what? Twiddle its thumbs?



  •  @dhromed said:

    @dgvid said:

    Several browsers had JavaScript support before DHTML came along.

    And this pre-DHTML javascript did what? Twiddle its thumbs?

    * Access and manipulate the contents of HTML forms (client-side validation).  This one has been around from the beginning, which is why so many clueless developers think that it's a suitable security barrier preventing the submission of invalid data.

    * Change the text in the status bar (This was a popular one for certian malware and practical jokes; e.g. create a link to goatse with a mouseover changing the status text to "http://www.geocities.com/"or something)

    *  Pop up annoying alert() dialogs.  Best when done in a loop.

    * Open and close windows

    * Go to a new page via window.location.href

     

    None of these affect the layout, structure, or HTML content of a page in any way. 



  • Also, document.write is not really DHTML - it only works while loading the page, it can't change things in response to pressing a button etc (so it's not really dynamic)



  • Now I'm feeling a bit paranoid. This is (more or less) the code I currently use to test minimal browser support. Any WTFery abound?

    <script type="text/javascript">
        <!--
        // check for DOM 2 support
        var domOK = (typeof document.getElementById != "undefined");
        // check for ECMAScript 3 support
        var jsOK = (typeof TypeError == "function");
        // leave detection page in a non-back-arrow-breaking fashion
        if (domOK && jsOK) {
            document.location.replace(actual_content_page);
        }
        // -->
    </script>
    You need to upgrade your browser.
    <noscript>
        This page requires browser scripting enabled yadda yadda etc.
    </script>



  • @Random832 said:

    Also, document.write is not really DHTML - it only works while loading the page, it can't change things in response to pressing a button etc (so it's not really dynamic)
    Aha... That distinction makes perfect sense, thanks!



  • @Zylon said:

    Now I'm feeling a bit paranoid. This is (more or less) the code I currently use to test minimal browser support. Any WTFery abound?

    Quite a bit.  Well, not WTF worthy, but bad practices all around.@Zylon said:

    <!--

     @Zylon said:

     

    <script type="text/javascript">

    Ok, that is good.  You do have the right script tag.

     @Zylon said:

    <!--

    Lose this. It hasn't been neede since Netscape version 3 something and it CAN cause trouble in XHTML, if we ever switch to that.  (Please don't switch to XHTML now -- the world isn't ready.)

    The rest of what you are doing is referred to as 'feature inference.'  You check for one thing and assume that if that exists, everything else you need does too.

    Please google for 'javascript FEATURE testing' where you'll find a number of ways to test for just the features you are using.

     I assume that the Javascript is just an enhancement and that if I browse your page using my ancient javascript but no DHTML features, that the fall backs will still let me use your page properly.

     



  •  I think the best way to check for features today is to not do it at all and instead leave it to a library like Prototype.



  • @r3jjs said:

    @Zylon said:
    <!--

    Lose this. It hasn't been neede since Netscape version 3 something and it CAN cause trouble in XHTML, if we ever switch to that.

    Ah, but if this were an XHTML document I'd have to be using those awful CDATA tags anyway. Plus I only use the comment tags in the initial detection page.

    @r3jjs said:

    The rest of what you are doing is referred to as 'feature inference.'  You check for one thing and assume that if that exists, everything else you need does too.

    True enough. But in the real world, is there any case where this would return a false positive? Are there really any browsers that support getElementById that don't implement DOM level 2? Are there any JavaScript engines that support exception handling that don't implement the ECMAScript 3 standard? Really now.



  • @Zylon said:

    But in the real world, is there any case where this would return a false positive? Are there really any browsers that support getElementById that don't implement DOM level 2? Are there any JavaScript engines that support exception handling that don't implement the ECMAScript 3 standard? Really now.

    Who even cares if there are?  If it works in IE6+, FF and Safari that's more than sufficient for most web apps.  You can even throw Opera in there if you want. 


Log in to reply