问题
I am trying to install PDF.JS in a CMS of sorts where the outer skeleton of the page is built for me, including the reference to jQuery (which is still version 1.10.2).
I have tried adding these two lines:
<script src="https://mozilla.github.io/pdf.js/build/pdf.js"></script>
<script src="https://mozilla.github.io/pdf.js/build/pdf.worker.js"></script>
And the running this command:
<script>
PDFJS.getDocument('/loc/testpdf.pdf');
</script>
But they return this error:
VM485:14 Uncaught ReferenceError: PDFJS is not defined
at eval (eval at <anonymous> (jquery.js?v=910.1:4), <anonymous>:14:1)
at eval (<anonymous>)
at jquery.js?v=910.1:4
at Function.globalEval (jquery.js?v=910.1:4)
at init.domManip (jquery.js?v=910.1:5)
at init.append (jquery.js?v=910.1:5)
at init.<anonymous> (jquery.js?v=910.1:5)
at Function.access (jquery.js?v=910.1:4)
at init.html (jquery.js?v=910.1:5)
I have been going round for a couple of hours trying to figure out what's wrong. Have I initialised it correctly or do we think it's related to the outdated version of jQuery?
Thanks
回答1:
try run the script after page loaded;
$(document).ready(function () {
PDFJS.getDocument('/loc/testpdf.pdf');
})
来源:https://stackoverflow.com/questions/48647838/uncaught-referenceerror-pdfjs-is-not-defined-when-initialising-pdf-js