Why does Javascript getUserMedia work only with Firefox?


I'm having trouble getting this code to work with browsers other than Firefox. The code is supposed to access the webcam. I can't find the problem. It does not work with chrome, internet explorer, Safari. It only works with Firefox. Does anyone have any answers why? How can I correct this code?

Here is the code:


function loading()
 var video = document.querySelector('#forVid');
navigator.getUserMedia = navigator.getUserMedia ||navigator.webkitGetUserMedia || navigator.mozGetUserMedia ||navigator.msGetUserMedia || navigator.oGetUserMedia;

   if (navigator.getUserMedia)
     var thevid = {video: true, audio: false};
     navigator.getUserMedia(thevid, handleVideo, forError)

function handleVideo(localmediastream)
      video.src = window.URL.createObjectURL(localmediastream);

function forError(e)
        // nothing


<body onload = "loading()">

<video id = "forVid" style="position:absolute; top:0; left:50;"autoplay="true" height="600" width="600">


Because this API has very less browser's support. Following link lists all Supported and Unsupported browsers for this API.