简体   繁体   中英

How would I reference exif.js in a Javascript file as I can't use getExif?

I am trying to use exif.js on my HTML page, but I don't think I'm referencing the exif.js file correctly, as window.onload = getExif returns an error saying it's undefined.

I have tried adding <script src="exif.js type="text/javascript"></script> to my HTML file and referencing my other file with <script src="myscript.js" type="text/javascript"></script> as well. It still doesn't seem to be working.

HTML :

<html>
    <head>
        <script src="exif.js" type="text/javascript"></script>
        <script src="myscript.js" type="text/javascript"></script>
    </head>
    <body>
        <img src="myimage.png" alt="" id="image">
        <div>
            <span id="metadata"></span>
        </div>
    </body>
</html>

Javascript :

window.onload = getExif;

img = document.getElementById("image")
EXIF.getData(img, function() {
        var allMetaData = EXIF.pretty(this);
        var allMetaDataSpan = document.getElementById("metadata");
        allMetaDataSpan.innerHTML = JSON.stringify(allMetaData,null, "\t");
});

The error I got was Uncaught ReferenceError: getExif is not defined . I'm not sure if I'm doing something wrong or not because everything looks good to me. Any help would be greatly appreciated.

You have no function named getExif defined. It's not something special exported or defined by exif.js , but simply a pattern they were following in the documentation examples. I imagine what you were going for is:

window.onload = getExif;

function getExif() {
    var img = document.getElementById("image");
    EXIF.getData(img, function() {
        var allMetaData = EXIF.pretty(this);
        var allMetaDataSpan = document.getElementById("metadata");
        allMetaDataSpan.innerHTML = JSON.stringify(allMetaData,null, "\t");
    });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM