-2
I have a Javascript file called "redirect.js", in which it has only two similar functions, which serve only to redirect to a specific page, "redirect.js", containing the following code:
export function redirectToCorrectPage() {
window.location.href = "right-answer.html";
}
export function redirectToIncorrectPage() {
window.location.href = "wrong-answer.html";
}
There are other 3 Scripts that I am trying to import these functions, but without success. 'redirect' script is in the same folder as these. So I’m trying to import it this way:
import { redirectToCorrectPage, redirectToIncorrectPage } from './redirect.js'
I’m having two kinds of mistakes:
- javascript - "Uncaught Syntaxerror: Cannot use import statement Outside a module"
- Uncaught Syntaxerror: Unexpected token '{'
On my HTML pages, which are directing to these scripts, all are with " script type='module' "
Anyway, my question is: What is the best way to import these functions, and why the way I did it is not working.
Thank you for your attention.
Please avoid long discussions in the comments; your talk was moved to the chat
– Maniero