0

In an attempt to skirt the following issues, https://bugs.chromium.org/p/chromium/issues/detail?id=321638, https://bugs.chromium.org/p/chromium/issues/detail?id=452685, and to make my Chrome packaged app work on Chrome 57+, I am loading an HTML page into the WebView as a data string, using FileReader() and the readAsDataURL() method.

The HTML file is your standard affair, containing references to external CSS and JS files.

Towards the bottom of the page, my JS scripts are called, again, pretty typical stuff, using <script src="../../shared/js/jquery-1.10.1.min.js"></script> for example. (Please ignore the terrible pathing).

Now, it seems like the HTML file is loaded and parsed correctly, but I get the age old error of Uncaught ReferenceError: $ is not defined.

Checking the erroneous line, it is in an inline (again, please don't shoot me) script that is after the jQuery script tag.

Are there any hidden caveats with loading HTML as a data string, specifically into a WebView?

Mr Pablo
  • 3,778
  • 7
  • 44
  • 94
  • could you type `jQuery` into console, is it also undefined? – john Smith May 12 '17 at 09:19
  • typing `jQuery` comes back as undefined, but that's because I'm not using `jQuery`, I'm using `$`. I can make such calls as `$('#my-div');` and get a result back. – Mr Pablo May 12 '17 at 09:55

1 Answers1

0

You may refer with this thread. You're encountering an error Uncaught ReferenceError: $ is not defined. maybe because you are calling the ready function before the jQuery JavaScript is included. You should put the references to the jQuery scripts first.

Here's another reference:

Community
  • 1
  • 1
abielita
  • 12,126
  • 2
  • 15
  • 52
  • Ah see, normally you would be correct, but in this case, the data encoded HTML file actually has ` – Mr Pablo May 15 '17 at 09:29