V
V
Volodymyr Palamar2021-08-29 18:11:15
JavaScript
Volodymyr Palamar, 2021-08-29 18:11:15

How to get GET parameters of the link from which the script was loaded?

What I mean is, for example, there is some script uploaded to github https;//musite.github.io/script.js

On the site example.com, we download it

<script defer src="https://mysite.github.io/script.js?param1=1&param2=2"></script>
<!-- в ссылке передаются статические параметры -->

Github was chosen simply for the example that there is no way on the server side to display the parameters in the script.

Is it possible from js to know from which script element it was loaded? Or some other way to get the parameters from the URL?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Volodymyr Palamar, 2021-08-29
@GORNOSTAY25

Found document.currentScript
https://developer.mozilla.org/currentScript

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question