2

I would like to invoke the saveValue function in every page but I get the below error message.

Uncaught ReferenceError: saveValue is not defined

Master page(inline script):

<script type="text/javascript">    
   var value = id;
   saveValue(value);
</script>

main.js

require( 'jquery', 'bootstrap' ], function ($, bootstrap) {
    var saveValue = function (value) {
         window.data.push(saveValue);
    };
});
siuri
  • 191
  • 2
  • 13
  • What comes first, the inline script or loading of the main.js? – pjones235 Dec 10 '18 at 16:03
  • @pjones235 it doesn't matter, `require` is async function, `saveValue(value)` is always called before `saveValue` is defined – ponury-kostek Dec 10 '18 at 16:08
  • Then I would assume jQuery or Bootstrap doesn't exist at the time the function is called. – pjones235 Dec 10 '18 at 16:10
  • @pjones235 — Which function? `require`? The whole point of `require` is that it loads them. `saveValue`? It is never called, it never exists in the global scope (and won't exist in the local scope of the function passed to `require` until the requirejs has loaded the dependancies. – Quentin Dec 10 '18 at 16:19
  • Do you have any solution to get the data? – siuri Dec 10 '18 at 16:22

0 Answers0