Save a node via javascript I want to be able to save a node when certain events happen in the browser. I.E the user changes tab. Is it possible to save a node in drupal using javascript?

Is there a javascript api tfor drupal? If not are there any contrib modules that add this? If it is custom code is needed is there an web service that can be called or would I need to role my own?
In order to achieve this on Drupal 7, you need to develop a custom module that does the following: 

Register a menu hook that will act as the endpoint where your javascript will send the data for the node to be created. 

Create a function that will be the callback of the hook and handle the actual creating and saving of the node. It can be something like this as mentioned in the answer above: 

$data = json_decode($_REQUEST['title']); 
$node = new stdClass;
$node-&gt;type = 'article';
$node-&gt;title = check_plain($data-&gt;title);
node_save($node);
echo json_encode(array('Status' =&gt; 'OK')); 
drupal_exit() 


Notice drupal_exit() is needed otherwise you get the whole page rendering. 
In order to set other properties for example the body, you need to know the structure, it is usually something like  

$node->fieldName[language][delta]['value'] eg, $node->body['und'][0]['value'] 

That's all it needs on the php side, now on the javascript side you will be needing to create an array containing the values for the node and submit it via ajax. Using jQuery it can be done like this: 

jQuery.ajax(
{
    url:  Drupal.settings.basePath + queryPath,  
type: 'POST',
dataType: 'json',
data:  {'data': JSON.stringify(queryParameters)},  
error: function (XMLHttpRequest, textStatus, errorThrown) 
{
    console.log(JSON.stringify(XMLHttpRequest));
    console.log(JSON.stringify(textStatus));
        console.log(JSON.stringify(errorThrown));
},
success: function (data) 
{
    console.log(data); 
    }
});


Data can contain anything returned from php... 

Have fun 

Update: 

A more general and concrete solution is available through the use of the Services module that allows you to define a REST api over the various content types you create. This way you don't need to write any custom code on the php side,