Friday, April 15, 2011

SslStream.DataAvailable not a valid function.

I am migrating C# code from using a NetworkStream to SSLStream, however where I use stream.DataAvailable I get the error:

Error 1 'System.Net.Security.SslStream' does not contain a definition for 'DataAvailable' and no extension method 'DataAvailable' accepting a first argument of type 'System.Net.Security.SslStream' could be found (are you missing a using directive or an assembly reference?)

now my local MSDN copy does not include DataAvailable as a member of SslStream however http://msdn.microsoft.com/en-us/library/dd170317.aspx says it does have the member DataAvailable. here is a copy of my code.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.IO;

namespace Node
{

  public static class SSLCommunicator
  {
    static TcpClient client = null;
    static SslStream stream = null;
    static List<byte> networkStreamInput = new List<byte>();
    public static void connect(string server, Int32 port)
    {
        try
        {
          client = new TcpClient(server, port);
          stream = new SslStream(client.GetStream(),false);
    ...
    ...
    ...
    public static List<DataBlock> getServerInput() 
    {
      List<DataBlock> ret = new List<DataBlock>();
      try
      {
      //check to see if stream is readable.
      if (stream.CanRead)
      {
        //Check to see if there is data available.
        if (stream.DataAvailable)
        {
          byte[] readBuffer = new byte[1024];
          int numberOfBytesRead = 0;
          //while data is available buffer the data.
          do
          {
            numberOfBytesRead = stream.Read(readBuffer, 0, readBuffer.Length);
            byte[] tmp = new byte[numberOfBytesRead];
            Array.Copy(readBuffer, tmp, numberOfBytesRead);
            networkStreamInput.AddRange(tmp);
          } while (stream.DataAvailable);
     ...

Also if you have a better way to get my output of the stream in to a managed array (there will be some parsing done on it later in the code) I would love the help. I am using Visual Studio 2008

--EDIT I just realized I linked to the embedded SDK, this is not a embedded system, so how do I see if data is available in the normal .net SDK?

From stackoverflow
  • The page you are looking at is for the .NET Micro Framework.

    According to this page for .Net 2.0 and this page for .Net 3.5, there is no DataAvailable property on SSLStream.

    Edit: Can't you just call Read() and see if you get anything back? i don't think this will block.

  • I am facing the same problem. Im trying to find out a way in which my client would know that the stream of data has ended. In my application, just like yours, i am running a loop with beginread and storing all collected data in a memorystream. However, i need to know that the data has completed and then i need to send the memorystream to another class for further processing. How did you get about this problem? I will greatly appreciate your help. Thanks.

PL/SQL Trigger - Dynamically reference :NEW or :OLD

Is it possible to dynamically reference the :NEW/OLD pseudo records, or copy them?

I'm doing a audit trigger for a very wide table, so would like to avoid having separate triggers for insert/delete/update.

When updating/inserting I want to record the :NEW values in the audit table, when deleting I want to record the :OLD values.

From stackoverflow
  • Why don't you use Oracle's built in standard or fine-grained auditing?

    Matthew Watson : Standard Edition.
  • You can use a compound trigger and programmatically check if it us I/U/D.

    Compound Triggers

    Regards K

    Matthew Watson : That is what I'm doing, but I'm trying to avoid having multiple insert statements within the trigger.
    Khb : I'm not sure I follow, are you doing something like this? CREATE OR REPLACE TRIGGER TRG BEFORE INSERT OR UPDATE OR DELETE ON TBL BEGIN IF INSERTING THEN ...(record :new) ELSEIF UPDATING THEN ...(record :new) ELSEIF DELETING THEN ...(record :old) END IF; ?
    Matthew Watson : I have a single insert statement INSERT INTO HIST ( EMP_ID, NAME ) VALUES (:NEW.EMP_ID , :NEW.NAME ) ; when deleting though, I want to use :OLD , not not have a seperate insert statement for that.
  • You could try:

    declare
      l_deleting_ind varchar2(1) := case when DELETING then 'Y' end;
    begin
      insert into audit_table (col1, col2)
      values
       ( CASE WHEN l_deleting_ind = 'Y' THEN :OLD.col1 ELSE :NEW.col1 END
       , CASE WHEN l_deleting_ind = 'Y' THEN :OLD.col2 ELSE :NEW.col2 END
       );
    end;
    

    I found that the variable was required - you can't access DELETING directly in the insert statement.

  • WOW, You want to have only ONE insert in your trigger to avoid what?

    *"I have a single insert statement INSERT INTO HIST ( EMP_ID, NAME ) VALUES (:NEW.EMP_ID , :NEW.NAME ) ; when deleting though, I want to use :OLD , not not have a seperate insert statement for that. "*

    It's a wide table. SO? It's not like there no REPLACE in text editors, you're not going to write the Insert again, just copy, paste, select, replace :NEW with :OLD.

    Tony does have a solution but I seriously doubt that performs better than 2 inserts would perform.

    What's the big deal?


    EDIT

    the main thing I'm trying to avoid is having to managed 2 inserts when the table changes. – Matthew Watson

    I battle this attitude all the time. Those who write Java or C++ or .Net have a built-in RBO... Do this, this is good. Don't do that, that's bad. They write code according to these rules and that's fine. The problem is when these rules are applied to databases. Databases don't behave the same way code does.

    In the code world, having essentially the same code in two "places" is bad. We avoid it. One would abstract that code to a function and call it from the two places and thus avoid maintaining it twice, and possibly missing one, etc. We all know the drill.

    In this case, while it's true that in the end I recommend two inserts, they are separated by an ELSE. You won't change one and forget the other one. IT'S Right There. It's not in a different package, or in some compiled code, or even somewhere else in the same trigger. They're right beside each other, there's an ELSE and the Insert is repeated with :NEW, instead of :OLD. Why am I so crazed about this? Does it really make a difference here? I know two inserts won't be worse than other ideas, and it could be better.

    The real reason is being prepared for the times when it does matter. If you're avoiding two inserts just for the sake of maintenance, you're going to miss the times when this makes a HUGE difference.

    INSERT INTO log
    SELECT * FROM myTable 
    WHERE flag = 'TRUE'
    
    ELSE                          -- column omitted for clarity
    
    INSERT INTO log
    SELECT * FROM myTable 
    WHERE flag = 'FALSE'
    

    Some, including Matthew, would say this is bad code, there are two inserts. I could easily replace 'TRUE' and 'FALSE' with a bind variable and flip it at will. And that's what most people would do. But if True is .1% of the values and 99.9% is False, you want two inserts, because you want two execution plans. One is better off with an index and the other an FTS. So, yes, you do have two Inserts to maintain. That's not always bad and in this case it's good and desirable.

    Matthew Watson : the main thing I'm trying to avoid is having to managed 2 inserts when the table changes.
  • Use a compound trigger, as others have suggested. Save the old or new values, as appropriate, to variables, and use the variables in your insert statement:

    declare
      v_col1  table_name.col1%type;
      v_col2  table_name.col2%type;
    begin
      if deleting then
        v_col1 := :old.col1;
        v_col2 := :old.col2;
      else
        v_col1 := :new.col1;
        v_col2 := :new.col2;
      end if;
    
      insert into audit_table(col1, col2)
      values(v_col1, v_col2);
    end;
    
    Matthew Watson : mm, yeh, was hoping to be able to just copy the record. oh well. thanks

Quick question on reflection in C#

I am getting started with the notion of test-driven development, and kind of failing since I am finding that I know what the test is going to be kind of, but I can't figure out how to get it to do what I want. What I have is a property that has a public getter and an internal setter. I'd like to test the functionality by accessing the internal setter from the unit test, but I can't figure out just how to do it. Here is the test:

 [Test()]
 public void HandleInput() {
  _requestType = _request.GetType();
  PropertyInfo propStdin =
   _requestType.GetProperty("StandardInput", BindingFlags.Public | BindingFlags.NonPublic);
  if(propStdin == null) {
   // Bug in the test.
   throw new Exception("There is a bug in the test. Reflection of stdin property returned null.");
  }
  MethodInfo setStdin = propStdin.GetSetMethod();

  // This will fail at the moment since nothing is here to make this happen.
  Assert.AreEqual("NewInputNewRequestInput", _request.StandardInput);
 }

Now, the problem is that when I run the test, I get:

[mono-2.4] mbt@zest:~/Projects/StaffASAP/Test.FastCGI/bin/Debug$ nunit-console2 Test.FastCGI.dll
NUnit version 2.4.8
Copyright (C) 2002-2007 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.

Runtime Environment - 
   OS Version: Unix 2.6.29.0
  CLR Version: 2.0.50727.1433 ( Mono 2.4 )

..F
Tests run: 2, Failures: 1, Not run: 0, Time: 0.111 seconds

Test Case Failures:
1) Test.FastCGI.tRequest.HandleInput : System.Exception : There is a bug in the test. Reflection of stdin property returned null.
at Test.FastCGI.tRequest.HandleInput () [0x00051] in /home/mbt/Projects/StaffASAP/Test.FastCGI/tRequest.cs:54
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00057] in /media/disk/mono-2.4/sources/mono-2.4/mcs/class/corlib/System.Reflection/MonoMethod.cs:159

So, I must be attempting to access the property incorrectly, but from looking at the documentation, I don't know what I am doing wrong. What am I doing wrong?

From stackoverflow
  • You may want to look at the InternalsVisibleTo assembly attribute:

    [Y]ou can expose an assembly's internal methods/properties/classes to a "friend" assembly. Normally internals are only accessible to members of the same assembly, and are often used to hide "plumbing" methods and utilities classes.

  • Here is a similar article on SO that deals with Unit tests, internal members and reflection..

  • Are you missing | BindingFlags.Instance in the GetProperty(...) call?

    It would be much nicer however to expose the internal variables to the test program through the InternalsVisibleTo attribute, as you don't need to rely on reflection, and refactoring will propagate if the test project is part of your solution in Visual Studio.

    Michael Trausch : Thanks for the additional pointer to BindingFlags.Instance. That works, as does the InternalsVisibleTo attribute. I've gone with using the InternalsVisibleTo attribute since it makes the tests easier to write and more readable, but the other info is great, too!
    Cecil Has a Name : While reflection is interesting and powerful, you'll find it is picky about the details.

SQL JOIN: ON vs Equals

Is there any significant difference between the following?

SELECT a.name, b.name FROM a, b WHERE a.id = b.id AND a.id = 1

AND

SELECT a.name, b.name FROM a INNER JOIN b ON a.id = b.id WHERE a.id = 1

Do SO users have a preference of one over the other?

From stackoverflow
  • No difference. I find the first format more readable and use the second format only when doing other types of joins (OUTER, LEFT INNER, etc).

  • There is no difference, but the readability of the second is much better when you have a big multi-join query with extra where clauses for filtering.
    Separating the join clauses and the filter clauses is a Good Thing :)

    Joel Coehoorn : There's no difference for this query, but for other queries there are some things you can doe with 'INNER JOIN' style syntax that you can't do with the a,b style syntax.
    Lars Mæhlum : Joel: Very true :)
  • The former is ANSI 89 syntax, the latter is ANSI 92.

    For that specific query there is no difference. However, with the former you lose the ability to separate a filter from a join condition in complex queries, and the syntax to specify LEFT vs RIGHT vs INNER is often confusing, especially if you have to go back and forth between different db vendors. I don't like the older syntax at all.

  • The second form is SQL92 compliant syntax. This should mean that it is supported by all current and future databases vendors. However , the truth is that the first form is so pervasive that it is also guaranteed to be around for longer than we care.

    Otherwise they are same in all respects in how databases treat the two.

  • There is no difference to the sql query engine.

    For readability, the latter is much easier to read if you use linebreaks and indentation.

    For INNER JOINs, it does not matter if you put "filters" and "joins" in ON or WHERE clause, the query optimizer should decide what to do first anyway (it may chose to do a filter first, a join later, or vice versa

    For OUTER JOINs however, there is a difference, and sometimes youll want to put the condition in the ON clause, sometimes in the WHERE. Putting a condition in the WHERE clause for an OUTER JOIN can turn it into an INNER JOIN (because of how NULLs work)

    For example, check the readability between the two following samples:

    SELECT c.customer_no, o.order_no, a.article_no, r.price
    FROM customer c, order o, orderrow r, article a
    WHERE o.customer_id = c.customer_id
    AND r.order_id = o.order_id
    AND a.article_id = r.article_id
    AND o.orderdate >= '2003-01-01'
    AND o.orderdate < '2004-01-01'
    AND c.customer_name LIKE 'A%'
    ORDER BY r.price DESC
    

    vs

    SELECT c.customer_no, o.order_no, a.article_no, r.price
    FROM customer c 
    INNER JOIN order o
       ON  o.customer_id = c.customer_id
       AND o.orderdate >= '2003-01-01'
       AND o.orderdate < '2004-01-01'
    INNER JOIN orderrow r
       ON  r.order_id = o.order_id
    INNER JOIN article a 
       ON  a.article_id = r.article_id
    WHERE  c.customer_name LIKE 'A%'
    ORDER BY r.price DESC
    
    Joel Coehoorn : Putting a condition in a where clause vs a join clause most certainly does matter for outer joins.
    Cybis : Why was this downvoted? I'm voting it back up. Brimstedt was simply showing that the second version is easier to read (and I agree with him). Joins and filters are, conceptually, two different things.
    Brimstedt : ah, yes for outer joins it makes a difference.. thanks for pointing it out, Ill edit my answer for completeness
    Brimstedt : Not that i care much about the downvote, but to the query engine, it does not matter. To humans it does, and I find it more readable. :-)
  • Whilst you can perform most tasks using both and in your case there is no difference whatsoever, I will always use the second at all times.

    1. It's the current supported standard
    2. It keeps joins in the FROM clause and filters in the WHERE clause
    3. It makes more complex LEFT, RIGHT, FULL OUTER joins much easier
    4. MSSQL Help is all based around that syntax therefore much easier to get help on your problem queries
  • While there is no difference technically, you need to be extra careful about doing joins using the first method. If you get it wrong by accident, you could end up doing a cartesian join between your a and b tables (a very long, memory & cpu intensive query - it will match each single row in a with all rows in b. Bad if a and b are large tables to begin with). Using an explicit INNER JOIN is both safer and easier to read.

Converting webpages from UTF-8 to ISO-8859-1 in linux

Anyone have a neat trick on how to convert a number of php and html files from UTF-8 to ISO-8859-1 in linux (Ubuntu)?

From stackoverflow
  • I think iconv is your answer...

    Form man iconv:

      NAME
          iconv - Convert encoding of given files from one encoding to another
    
      SYNOPSIS
          iconv -f encoding -t encoding inputfile
    
      DESCRIPTION
          The iconv program converts the encoding of characters in inputfile from one coded 
          character set to another. The result is written to standard output unless otherwise 
          specified by the --output option.
    
          .....
    

    So you could probably do a

    find $my_base_dir -name "*.php" -o -name "*.html" -exec sh -c "( \
       iconv -t ISO88592 -f UTF8 {} -o {}.iconv ; \
       mv {}.iconv {} ; \
    )" \;
    

    This will recursively find the appropriately named files and re-encode them (the temporary file is necessary, as iconv will truncate output before starting to work).

  • Ubuntu has recode

    $ sudo apt-get install recode
    $ recode UTF-8..latin1 *.php
    

    Recursively, thanks to Ted Dziuba:

    $ find . -name "*.php" -exec recode UTF-8..latin1 {} \;
    
    David Zaslavsky : recode is a fairly standard Linux program - not so standard that it's always installed by default, but it should be available on all distributions, not just Ubuntu.
    Svish : how can I do this recursive?
    Ted Dziuba : Recursively, it's find . -name "*.php" -exec recode UTF-8..latin1 {}\;
    Luiz Damim : +1 Found your answer while searching google for this conversion. It saved my day :)

How to include an html page into an html page

Hi friends,

I want to include an html page inside an html page. Is it possible? Please give me the code. I dont want to do it in PHP, I know that in PHP, we can use include for this situation, how can I achieve the same purely in html without using the iframe and frame concept?

From stackoverflow
  • <iframe src="page.html"></iframe>
    

    You will need to add some styling to this iframe. You can specify width, height, and if you want it to look like a part of the original page include fameborder="0".

    There is no other way to do it in pure HTML. This is what they were built for, it's like saying I want to fry an egg without an egg.

  • If you're just trying to stick in your own HTML from another file, and you consider a Server Side Include to be "pure HTML" (because it kind of looks like an HTML comment and isn't using something "dirty" like PHP):

    <!--#include virtual="/footer.html" -->
    
    Sam152 : This isnt a pure HTML solution is it?
    Daniel LeCheminant : @Sam152: Shhh! ;-]
    Sam152 : Yeah +1. Its probably the better way of doing it. He also says that he doesn't want to use an iframe, so who knows which solution will work best.
    praveenjayapal : Hey, here i got a idea, i have included the whole content inside the javascript - document.write. then place the javascript file inside the html. It working
  • If you mean client side then you will have to use JavaScript or frames.
    Simple way to start, try jQuery

    $("#links").load("/Main_Page #jq-p-Getting-Started li");
    

    More at jQuery Docs

    If you want to use IFrames then start with Wikipedia on IFrames

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
      <head>
            <title>Example</title>
      </head>
      <body>
            The material below comes from the website http://example.com/
            <iframe src="http://example.com/" height="200">
                Alternative text for browsers that do not understand IFrames.
            </iframe>
       </body>
    </html>
    
    praveenjayapal : Hey, here i got a idea, i have included the whole content inside the javascript - document.write. then place the javascript file inside the html. It working
  • You can use an object element-

    <object type="text/html" data="urltofile.html"></object>
    

    Or, on your local server, Ajax can return a string of html (responseText) that you can use to document.write a new window, or edit out the head and body tags and add the rest to a div or other block element in the current page.

  • @PraveenJayapal :: How to include the HTML content in a JAVASCRIPT file?? And how to place it inside the HTML page?

What is the best technique for consistent form, function between all web browsers (including Google Chrome)?

Short version: What is the cleanest and most maintainable technique for consistant presentation and AJAX function across all browsers used by both web developers and web developers' end-users?

  • IE 6, 7, 8
  • Firefox 2, 3
  • Safari
  • Google Chrome
  • Opera

Long version: I wrote a web app aimed at other web developers. I want my app to support the major web browsers (plus Google Chrome) in both presentation and AJAX behavior.

I began on Firefox/Firebug, then added conditional comments for a consistent styling under IE 6 and 7. Next, to my amazement, I discovered that jQuery does not behave identically in IE; so I changed my Javascript to be portable on FF and IE using conditionals and less pure jQuery.

Today, I started testing on Webkit and Google Chrome and discovered that, not only are the styles inconsistant with both FF and IE, but Javascript is not executing at all, probably due to a syntax or parse error. I expected some CSS work, but now I have more Javascript debugging to do! At this point, I want to step back and think before writing piles of special cases for all situations.

I am not looking for a silver bullet, just best practices to keep things as understandable and maintainable as possible. I prefer if this works with no server-side intelligence; however if there is a advantage to, for example, check the user-agent and then return different files to different browsers, that is fine if the total comprehensibility and maintainability of the web app is lower. Thank you all very much!

From stackoverflow
  • Just so you've got one less browser to worry about, Chrome uses the same rendering engine as Safari. So if it works in Safari, it should work exactly the same in Chrome.

    See this post on Matt Cutts' blog.

    Google Chrome uses WebKit for rendering, which is the same rendering engine as Apple’s Safari browser, so if your site is compatible with Safari it should work great in Chrome.

    Update: Looks like this is now out-dated info. Please see Vox's comment on this answer.

    VoxPelli : Chrome and Safari are using different javascript engines so it might differ and in fact I've also seen some rendering inconsistencies - perhaps originating from the fact that Safari and Chrome probably are running different builds of Webkit
  • For UI, check out Ext.

    It's great as a standalone library, though it can also be used with jQuery, YUI, Prototype and GWT.

    Samples: http://extjs.com/deploy/dev/examples/samples.html

  • Chrome is actually a little different to Safari, it uses a completely different javascript implementation and problems have been reported with both prototype and jquery. I wouldn't worry about it too much for now, it's still an early beta version of the browser and such inconsistencies will probably be treated as bugs. Here's the bug report.

  • I am in a similar situation, working on a web app that is targeted at IT professionals, and required to support the same set of browsers, minus Opera.

    Some general things I've learned so far:

    • Test often, in as many of your target browsers as you can. Make sure you have time for this in your development schedule.
    • Toolkits can get you part of the way to cross-browser support, but will eventually miss something on some browser. Plan some time for debugging and researching fixes for specific browsers.
    • If you need something that's not in a toolkit and can't find a free code snippet, invest some time to write utility functions that encapsulate the browser-dependent behavior.
    • Educate yourself about known browser bugs, so that you can steer your implementation around them.

    A few more-specific things I've learned:

    • Use conditional code based on the user-agent only as a last resort, because different generations of the "same" browser may have different features. Instead, test for standards-compliant behavior first — e.g., if(node.addEventListener)..., then common non-standard functions — e.g., if(window.attachEvent)..., and then, if you must, look at the user-agent for a specific browser type & version number.
    • Knowing when the DOM is 'ready' for script access is different in just about every browser. A good toolkit will abstract this for you.
    • Event handlers are different in just about every browser. A good toolkit will abstract this for you.
    • Creating DOM elements, particularly form controls or elements with attributes, can be tricky with document.createElement and element.setAttribute. While not standard (and kinda yucky), using node.innerHTML with strings that contain bits of HTML seems to be more reliable across browser types. I have yet to find a toolkit that will let you use element.setAttribute to add a 'name' to a form element in IE.
    • CSS differences (and bugs) are just as important as JS differences.
    • The 'core' Javascript features (String, Date, RegExp, Array functions) seem to be pretty reliable and consistent across browsers, especially relative to the DOM/CSS/Window functions. There's some small joy in the fact that the language isn't entirely different on every platform. :-)

    I haven't really run into any Chrome-specific JS bugs, but it's always one of the first browsers I test.

    HTH

  • One "silver bullet" you may consider turning to is Google Web Toolkit (GWT).

    I believe it supports all the browsers you are interested in, and gives you the ability to code your UI in a Java-compatible IDE such as Eclipse. The advantage of this is you can use IDE tools for code completion and compile-time error checking, which greatly improves development on large-scale UI projects.

    If you use GWT UI components, it will hide a lot of browser-specific nastiness from having to be dealt with, but when you compile, will create a compact, deploy file for each browser platform. This way you never download any IE-specific code if you are viewing the app in Firefox. You will also have a client-side stub generated which will load the appropriate compiled bundle of JS. To sweeten the deal, these files are cacheable, so perceived performance is generally improved for returning visitors.

    system PAUSE : Thanks! It looks nifty, but it would be difficult to migrate my existing JavaScript codebase (with jQuery/YUI/ie7-js/etc) to a purely Java codebase, esp. without much Java expertise on the team. But nice to find that Java/J2EE is not required on the server, and that IE6 is supported.
  • If you're starting from a base reset or framework and have accounted for IE and it's still all freaky, you may want to recheck the following:

    • Everything validates? CSS and HTML?
    • Any broken links to an included file (js, css, etc?). In Chrome/Safari, if your stylesheet link is busted, all of your links might end up red. (something to do with the default 404 styling I think)
    • Any odd requirements of your js plugins that you might be using? (does the css file have to come before the js file, like with jquery.thickbox?)
  • The landscape has evolved considerably to accommodate cross-browser development. jQuery, Prototype and other frameworks exist for cross-browser Javascript. CSS resets are good for starting on a common blank canvas for all browsers. BluePrint and 960 are both CSS frameworks to help with layouts using CSS grid layouts techniques that seems to be getting very popular these days.

    As for other CSS quirks across the different browsers, there is no holy grail here and the only option is to test you website across different browsers and use this awesome resource and definitely join a mailing list to save up soem time.

    If you are working on high volume production site then you can use a service like browsercam.com in the end game to ensure the site doesn't break horribly in some browser.

    Lastly, don't try to make the site look the same in every browser. Your primary design should target IE/FF and you should be okay with reasonable compromises on others. Use the graded browser chart to narrow in on browser support.

    As for best practices, starting using wireframes on blank paper or a service like Balsamiq mockups. I am still surprised how many developers start with an editor instead of a wireframe but then again I only switched a year back before realizing how big a time saver it is. Have clean seperation of layout (HTML), presentation (CSS) and behaviors (Javascript). There should be no styling elements in HTML, no presenation in Javascript (use .addClass('highlight') instead of .css({'background-color': 'red'});).

    If you are not familiar with any of the bold terms in this post, Googling them should be fruitful for your web development career and productivity.

  • If your very top priority is exactly consistent presentation on all the browsers listed with no disparities, you should probably be looking at AS3 and Flex.

  • Personally, I use Mootools as a simple lightweight javascript framework. It is simple to use and supports all the browsers above (except Chrome, but that seems to work too as far as I can tell).

    Also, to ensure consistency across the browsers, I get a feature/style/behaviour/etc. to work in one browser first (usually Firefox 3 with firebug), then immediately check to make sure it works in all the other browsers (leaving IE6 for last). If it doesn't, I inveset the time to fix it right away, because otherwise I know I won't have time later (in my experience, getting things to work cross-browser takes about 50% of my dev. time ;-) )

  • I've found four things helpful in developing JavaScript applications:

    • Feature detection
    • Libraries
    • Iterative Development using Virtualization
    • JavaScript: The Definitive Guide, Douglas Crockford & John Resig

    Feature Detection

    Use reflection to ask if the browser supports the desired feature. If you want to know what event handling a browser supports, you can if(el.addEventHandler) for W3C compliance, if(el.attachEvent) for the IE-type, and finally fall back on el.['onSomeEvent'].

    ONE BIG BUT!

    Browsers sometimes lie about what features they support. I can't remember, but I ran into an issues where Firefox implemented a DOM feature, but would return false if you tested for that feature!

    Libraries

    Since you're already working with jQuery, I'll save the explanation. But if you're running into problems you may want to consider YUI for it's wonderful cross-browser compatibility. They even work together.

    Iterative Development with Virtualization

    Perhaps my best advice: Run all your test environment's at once. Get a Linux distro, Compiz Fusion and a bunch of RAM. Download a copy of either VMWare's VMWare Server or Sun's Virtual Box and install a few operating systems. Get images for Windows XP, Windows Vista and Mac OS X.

    The basic idea is this: Compiz Fusion gives you 4 Desktops mapped onto a Cube. 1 of these desktops is your Linux computer, the next your Virtutual Windows XP box, the one after that Vista, the last Mac OS X. After writing some code, you alt-tab into virtual computer and check out your work. Plus it looks awesome.

    JavaScript: The Definitive Guide, Douglas Crockford & John Resig

    These three sources provide most of my information for JavaScript development. The Definitive guide is perhaps the best reference book for JavaScript.

    Douglas Crockford is a JavaScript guru (I hate the word) at Yahoo. Lookup his series "Douglas Crockford Theory of the DOM", "Douglas Crockford Advanced JavaScript", "Douglas Crockford Theory of the Dom", and ""Douglas Crockford The Good Parts" on Yahoo! Videos.

    John Resig (as you know) wrote jQuery. His website at ejohn.org contains a wealth of JavaScript information, and if you dig around on Google you'll find he's given a number of presentations on defensive JavaScript techniques.

    ... Good luck!

    jhs : rooney, thank you for your advice. You imply that the troublemaker is Javascript, not so much HTML/CSS--a good point. Virtualization is an interesting solution. I've been using EC2 recently for throwaway test work. Maybe it's time for a RAM upgrade :)
  • Validating your javascript with a "good parts" + browser on JsLint.com makes it less likely to have JavaScripts behaving differently in FF, Safari etc.

    Otherwise - using standards and validating your code as well as building on existing techniques like jQuery should make your site behave the same in all browsers except IE - and there's no magic recipe for IE - it's just bugs everywhere...