1

I'm really a beginner at Javascript. How can I use a script variable from HTML to another js file? I have tried to import and export module. But, I couldn't work.

Here is the js.fiddle: https://jsfiddle.net/hfngowtq/

and that is my error:

1.js:1 GET .../new.html net::ERR_ABORTED 404 (NOT FOUND)

Quoc-Anh Nguyen
  • 4,798
  • 1
  • 22
  • 34
dberkovski
  • 46
  • 3
  • 2
    Please read [Something on my web site doesn't work. Can I just paste a link to it?](http://meta.stackoverflow.com/questions/125997/something-on-my-web-site-doesnt-work-can-i-just-paste-a-link-to-it). Questions that depend on external resources to be understood become useless when the external resource goes away or is fixed. Create a [MCVE] and put it in **the question itself** instead. Stackoverflow does support [inline live demos](https://stackoverflow.blog/2014/09/16/introducing-runnable-javascript-css-and-html-code-snippets/) – Quentin Feb 10 '21 at 12:16
  • You've tagged this [tag:flask], what does that have to do with the question? – Quentin Feb 10 '21 at 12:16
  • Does this answer your question? [Passing Variable through JavaScript from one html page to another page](https://stackoverflow.com/questions/27765666/passing-variable-through-javascript-from-one-html-page-to-another-page) – Ahmad Habib Feb 10 '21 at 12:18
  • @AhmadHabib — It doesn't seem to be about multiple HTML pages. – Quentin Feb 10 '21 at 12:25
  • It's unclear why you are asking about passing data between scripts when your error is a simple 404 not found. – Quentin Feb 10 '21 at 12:26

2 Answers2

0

You can just use local storage instead of variables. It will store values across js files

Gamer4717
  • 51
  • 7
-1

A simple solution is using a global variable.

window.a = "123" // your HTML 
console.log(window.a) // your script
Quoc-Anh Nguyen
  • 4,798
  • 1
  • 22
  • 34