javascript内のカメラを起動させる関数をHTMLから呼び出したいのですが、
書き方がわかりません。
以下のコードのnavigator.camera.getPictureの関数を使いたいです。
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ alert("tesuto"); var app = { // コンストラクタ //initializeは初期化 initialize: function() { this.bindEvents(); }, // 'deviceready'はCordovaを全て読み込んでから //bindEventsは起動時に必要となる全てのイベントをバインド(関連付け)する //addEventListenerは第一引数にイベント名、第二引数にイベントリスナ(呼び出す関数)、第三引数に真偽値を入れつ。 //第一引数にonはつけない bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); alert("tesuto2"); }, // deviceready Event Handler // onDeviceReady: function() { app.receivedEvent('deviceready'); alert("tesuto3"); //カメラへのオプション var options = { quality: 50, destinationType: navigator.camera.DestinationType.FILE_URI }; //カメラを起動する。 navigator.camera.getPicture(function(imageData) { alert(imageData); }, function() { alert('fail'); }, options); //setTimeoutは第一引数に呼び出したい関数、第二引数に待機時間を設定する。2000=2秒 //setTimeoutのTは大文字でなければ実行されない。 setTimeout(navigator.camera.getPicture,2000); }, // Update DOM on a Received Event receivedEvent: function(id) { //document.getElementById(id);は指定の引数を持つ要素を返す。 var parentElement = document.getElementById(id); //セレクタにマッチする文章中の最初の要素を返す。 //セレクタとはスタイルを適用する対象のこと、CSS var listeningElement = parentElement.querySelector('.listening'); var receivedElement = parentElement.querySelector('.received'); //指定の要素に新しい属性を追加もしくは指定の要素に存在する値を変更する。 //第一引数に属性名、第二引数に変更したい値を入れる。 listeningElement.setAttribute('style', 'display:none;'); receivedElement.setAttribute('style', 'display:block;'); //console.logはコンソールにメッセージを出力させる関数。 console.log('Received Event: ' + id); } }; app.initialize();
あまりブラウザには詳しくありませんが、navigator.cameraとは何ですか?標準のブラウザにWindow.navigator.cameraは存在しないと思います。使用しているライブラリ等を明記したほうが良いと思います。