1

I have a web app, that opens a camera using the solution here:

How to access a mobile's camera from a web app?

But, how can I run a callback function, when I return from the camera app back to the web app?

Thanks

Community
  • 1
  • 1
omega
  • 40,311
  • 81
  • 251
  • 474
  • You can use blur and focus events with regard to the window. See: http://stackoverflow.com/questions/1760250/how-to-tell-if-browser-tab-is-active – Rodrigo C Mar 02 '16 at 01:03
  • I tried that, but it didn't fire when I opened the camera. – omega Mar 02 '16 at 01:07

1 Answers1

0

You said you'd tried the blur/focus methods, but did you try the visibility api per https://stackoverflow.com/a/19519701/6004366 ?

I wrote a short script and tested it out, going to my camera and then back, and it logs both that it lost visibility and regained it.

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>

<input type="file" accept="image/*" capture="camera">

<ul id="log">
</ul>

<script type="text/javascript">
    var vis = (function(){
        var stateKey, eventKey, keys = {
            hidden: "visibilitychange",
            webkitHidden: "webkitvisibilitychange",
            mozHidden: "mozvisibilitychange",
            msHidden: "msvisibilitychange"
        };
        for (stateKey in keys) {
            if (stateKey in document) {
                eventKey = keys[stateKey];
                break;
            }
        }
        return function(c) {
            if (c) document.addEventListener(eventKey, c);
            return !document[stateKey];
        }
    })();

    vis(function(){
        var logitem = vis() ? 'Visible' : 'Not visible';

        var loglist = document.getElementById("log");

        var node = document.createElement("LI");  
        var textnode = document.createTextNode(logitem);
        node.appendChild(textnode); 

        loglist.appendChild(node);

    });
</script>

</body>
</html>
Community
  • 1
  • 1
Rodrigo C
  • 151
  • 6