Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get currentScript if it has type="module"

I enqueue JS file as a script with type="module" and need to get the src attribute of the script inside of the script

But if I trying

document.currentScript

it returns null

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is there a similar way as currentScript for type="module" ?


Ok, I see there is a duplicate so I’ve closed my question

>Solution :

import.meta

You can use import.meta.

For example:

In page.html:

<script src="module1.js" type="module"></script> 

In module1.js:

import './module2.js';
console.log(import.meta);

In module2.js:

console.log(import.meta);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading