I am trying to use the estimateGas function in Web3 to estimate how much gas it would cost to run a function in my contract. As an example of how this would normally be used, in geth I can run a command like the following and get something back (21001):

Thanks - I'm still having trouble estimating gas cost of a specific function in a contract though (eg. for a contract I've deployed MyContract, and a function SetMessage which takes one parameter as in my post)
– ZhouWJul 19 '17 at 8:35

You probably did not instantiate an instance of web3, which is not necessary in the geth console but required for using web3 in the browser. Instantiating an instance of web3 requires that you specify a provider, for which you have multiple options (connecting to a locally running node, using MetaMask, a testRPC, etc).