每隔一段时间运行一个例程

时间:2011-03-21 08:34:06

标签: javascript setinterval

我想知道这个主板上是否有任何javascript专家,我需要实现Jpegcam,以便它能够以2分钟的间隔自动捕获图片,而无需使用拍摄快照按钮。我希望代码能够以2分钟的间隔自动运行take_snapshot例程。任何有想法的人。

`     

<!-- Configure a few settings -->
<script language="JavaScript">
    webcam.set_api_url( 'test.php' );
    webcam.set_quality( 90 ); // JPEG quality (1 - 100)
    webcam.set_shutter_sound( false ); // play shutter click sound
    webcam.set_stealth( true );

</script>

<!-- Next, write the movie to the page at 320x240 -->
<script language="JavaScript">
    document.write( webcam.get_html(320, 240) );
</script>

<!-- Some buttons for controlling things -->
<br/><form>
    <input type=button value="Configure..." onClick="webcam.configure()">
    &nbsp;&nbsp;
    <input type=button value="Take Snapshot" onClick="take_snapshot()">
</form>

<!-- Code to handle the server response (see test.php) -->
<script language="JavaScript">
    webcam.set_hook( 'onComplete', 'my_completion_handler' );

    function take_snapshot() {
        // take snapshot and upload to server
        document.getElementById('upload_results').innerHTML = '<h1>Uploading...</h1>';
        webcam.snap();
    }

    function my_completion_handler(msg) {
        // extract URL out of PHP output
        if (msg.match(/(http\:\/\/\S+)/)) {
            var image_url = RegExp.$1;
            // show JPEG image in page
            document.getElementById('upload_results').innerHTML = 
                '<h1>Upload Successful!</h1>' + 
                '<h3>JPEG URL: ' + image_url + '</h3>' + 
                '<img src="' + image_url + '">';

            // reset camera for another shot
            webcam.reset();
        }
        else alert("PHP Error: " + msg);
    }
</script>`

1 个答案:

答案 0 :(得分:0)

setInterval(take_snapshot, 1000 * 60 * 2);